Skip to content

Commit 8ac2c1f

Browse files
committed
Fix leftover /tmp/manhole-pid sockets in the tests
manhole.install() registers an exit function removing the manhole socket, but atexit function do not run when process is terminated by an unhandled signal. In the fork tests, we avoid this issue by terminating child processes with SIGINT, however the test child processes, created by the process_tests library, are terminate using SIGTERM in TestProcess.__exit__. Adding SIGTERM signal handler fixed this issue. We probably need to document this as a workaround for issue ionelmc#8
1 parent e2ff0b1 commit 8ac2c1f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/test_manhole.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@
2626
SOCKET_PATH = '/tmp/manhole-socket'
2727

2828

29+
def handle_sigterm(signo, frame):
30+
# Simulate real termination
31+
print("Terminated")
32+
sys.exit(128 + signo)
33+
34+
35+
# Handling sigterm ensure that atexit functions are called, and we do not leave
36+
# leftover /tmp/manhole-pid sockets.
37+
signal.signal(signal.SIGTERM, handle_sigterm)
38+
39+
2940
def is_module_available(mod):
3041
try:
3142
return imp.find_module(mod)

0 commit comments

Comments
 (0)