Skip to content

Commit

Permalink
Disables siginterrupt for SIGUSR1 (#1844)
Browse files Browse the repository at this point in the history
I've recently started using SIGUSR1 to stop old workers on deploy and each
deploy has resulted in all MapReduce tasks dying with
`IOError: [Errno 4] Interrupted system call`. Setting siginterrupt to
False for SIGUSR1 prevents this error for me.
  • Loading branch information
daveFNbuck authored and Tarrasch committed Sep 12, 2016
1 parent 2d0e4a1 commit 6d7a958
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions luigi/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ def __init__(self, scheduler=None, worker_id=None, worker_processes=1, assistant
if not self._config.no_install_shutdown_handler:
try:
signal.signal(signal.SIGUSR1, self.handle_interrupt)
signal.siginterrupt(signal.SIGUSR1, False)
except AttributeError:
pass

Expand Down
20 changes: 20 additions & 0 deletions test/worker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ def test_stop_getting_new_work(self):
self.w.run()
self.assertFalse(d.complete())

@mock.patch('luigi.worker.signal')
def test_signal_interrupt_disabled(self, worker_signal):
w = Worker(scheduler=self.sch)
worker_signal.signal.assert_called_once_with(worker_signal.SIGUSR1, w.handle_interrupt)
worker_signal.siginterrupt.assert_called_once_with(worker_signal.SIGUSR1, False)

@mock.patch('luigi.worker.signal')
def test_signal_interrupt_not_disabled_without_shutdown_handler(self, worker_signal):
Worker(scheduler=self.sch, no_install_shutdown_handler=True)
self.assertEqual(0, worker_signal.signal.call_count)
self.assertEqual(0, worker_signal.siginterrupt.call_count)

@mock.patch('luigi.worker.signal')
def test_signal_interrupt_ok_to_not_exist(self, worker_signal):
worker_signal.siginterrupt.side_effect = AttributeError
w = Worker(scheduler=self.sch) # may fail due to the AttributeError

# we still register the handler when the siginterrupt disable fails
worker_signal.signal.assert_called_once_with(worker_signal.SIGUSR1, w.handle_interrupt)

def test_disabled_shutdown_hook(self):
w = Worker(scheduler=self.sch, keep_alive=True, no_install_shutdown_handler=True)
with w:
Expand Down

0 comments on commit 6d7a958

Please sign in to comment.