Skip to content
Snippets Groups Projects
Commit f57d6f3f authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

When aborting a subprocess, try to terminate it before killing it

parent 9f48c59b
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ changed functionality, fixed bugs). ...@@ -10,6 +10,7 @@ changed functionality, fixed bugs).
- Include `exr-merge` task type in default configuration, which is required for progressive - Include `exr-merge` task type in default configuration, which is required for progressive
rendering. rendering.
- Prevent outgoing queue saturation by not fetching a new task when the queue is too large. - Prevent outgoing queue saturation by not fetching a new task when the queue is too large.
- When aborting a subprocess, try to terminate it before killing it.
- Changed some of the configuration defaults to more sensible values (mostly queueing up larger - Changed some of the configuration defaults to more sensible values (mostly queueing up larger
amounts of logs before pushing to Flamenco Manager). amounts of logs before pushing to Flamenco Manager).
......
...@@ -459,11 +459,32 @@ class AbstractSubprocessCommand(AbstractCommand): ...@@ -459,11 +459,32 @@ class AbstractSubprocessCommand(AbstractCommand):
self._log.debug("No process to kill. That's ok.") self._log.debug("No process to kill. That's ok.")
return return
self._log.info('Aborting subprocess') self._log.info('Terminating subprocess')
try:
self.proc.terminate()
except ProcessLookupError:
self._log.debug("The process was already stopped, aborting is impossible. That's ok.")
return
except AttributeError:
# This can happen in some race conditions, it's fine.
self._log.debug("The process was not yet started, aborting is impossible. That's ok.")
return
timeout = 5
try:
retval = await asyncio.wait_for(self.proc.wait(), timeout,
loop=asyncio.get_event_loop())
except asyncio.TimeoutError:
pass
else:
self._log.info('The process aborted with status code %s', retval)
return
self._log.warning('The process did not stop in %d seconds, going to kill it', timeout)
try: try:
self.proc.kill() self.proc.kill()
except ProcessLookupError: except ProcessLookupError:
# The process is already stopped, so killing is impossible. That's ok.
self._log.debug("The process was already stopped, aborting is impossible. That's ok.") self._log.debug("The process was already stopped, aborting is impossible. That's ok.")
return return
except AttributeError: except AttributeError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment