Skip to content

Commit

Permalink
Catch signal handler change error (#1147)
Browse files Browse the repository at this point in the history
The interruptible signal handle was incompatible with dask, it would trigger the following error:
```
Exception: "ValueError('signal only works in main thread of the main interpreter')"
```

This PR fixes the problem by catching the error and keeping the original signal handler in that case.

Authors:
  - Tamas Bela Feher (https://github.com/tfeher)

Approvers:
  - Corey J. Nolet (https://github.com/cjnolet)

URL: #1147
  • Loading branch information
tfeher authored Jan 18, 2023
1 parent 0cefbfb commit 187ff9e
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions python/pylibraft/pylibraft/common/interruptible.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ def cuda_interruptible():
with nogil:
dereference(token).cancel()

oldhr = signal.signal(signal.SIGINT, newhr)
try:
oldhr = signal.signal(signal.SIGINT, newhr)
except ValueError:
# the signal creation would fail if this is not the main thread
# That's fine! The feature is disabled.
oldhr = None
try:
yield
finally:
signal.signal(signal.SIGINT, oldhr)
if oldhr is not None:
signal.signal(signal.SIGINT, oldhr)


def synchronize(stream: Stream):
Expand Down

0 comments on commit 187ff9e

Please sign in to comment.