Skip to content

Commit 504141b

Browse files
authored
Safely retrieve original SIGINT and SIGTERM handlers
1 parent c4b7b34 commit 504141b

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

dirlock/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@
2020
# keep a list of currently acquired locks
2121
# so these can be cleaned up on exit
2222
_allActiveLocks = set()
23-
# we don't want to call the original handler
24-
original_sigint_handler = signal.getsignal(signal.SIGINT)
25-
original_sigterm_handler = signal.getsignal(signal.SIGTERM)
23+
24+
# we don't want to miss the original handler
25+
try:
26+
original_sigint_handler = signal.getsignal(signal.SIGINT)
27+
except Exception:
28+
pass
29+
30+
try:
31+
original_sigterm_handler = signal.getsignal(signal.SIGTERM)
32+
except Exception:
33+
pass
2634

2735

2836
# function to clean up all active locks

0 commit comments

Comments
 (0)