Skip to content

Commit

Permalink
Merge pull request #48 from UnholyDk/fix-signals-when-processes-start
Browse files Browse the repository at this point in the history
Restore signals for successful termination of processes
  • Loading branch information
bugrimov committed Feb 2, 2024
2 parents 69ebf7e + cc92772 commit 7d30f76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 1.11.2
- restore signals for successful termination of processes during flow.stop() if they were overridden

# 1.11.1
- Update setup requirements: add extras - aiohttp, numpy

Expand Down
11 changes: 11 additions & 0 deletions aqueduct/worker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import multiprocessing as mp
import queue
import signal
import sys
from threading import BrokenBarrierError
from time import monotonic
Expand Down Expand Up @@ -233,12 +234,22 @@ def _post_handle(self, task: BaseTask):
)
queue_out.put(task)

def _fix_signals(self):
""" Sometimes some web frameworks (e.g. unicorn) override signal handlers.
If processes use start method fork,
so when we call flow.stop() processes do not terminate and hang.
Here we restore the signals we need.
"""
signal.signal(signal.SIGTERM, signal.Handlers.SIG_DFL)
signal.signal(signal.SIGINT, signal.default_int_handler)

def loop(self, pid: int, start_barrier: mp.Barrier):
"""Main worker loop.
The code below is executed in a new process.
"""
log.info(f'[Worker] initialising handler {self.name}')
self._fix_signals()
self._start()
log.info(f'[Worker] handler {self.name} ok, waiting for others to start')

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
setup(
name='aqueduct',
packages=find_packages(),
version='1.11.1',
version='1.11.2',
license='MIT',
license_files='LICENSE.txt',
author='Data Science SWAT',
Expand Down

0 comments on commit 7d30f76

Please sign in to comment.