Skip to content

Commit f979048

Browse files
committed
Make SIGINT handler kill the process tree
The std lib's `pdb` internals override SIGINT handling whenever one enters the debugger repl. Force a handler that kills the tree if SIGINT is triggered from the root actor, otherwise igore it since supervised children should be managed already. This resolves an issue with guest mode where `pdb` causes SIGINTs to be swallowed resulting in the host loop never terminating the process tree.
1 parent 7431e8e commit f979048

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tractor/_debug.py

+16
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ async def _acquire_debug_lock(
196196
log.debug(f"TTY lock released, remote task: {task_name}:{uid}")
197197

198198

199+
def handler(signum, frame, *args):
200+
"""Specialized debugger compatible SIGINT handler.
201+
202+
In childred we always ignore to avoid deadlocks since cancellation
203+
should always be managed by the parent supervising actor. The root
204+
is always cancelled on ctrl-c.
205+
"""
206+
if is_root_process():
207+
tractor.current_actor().cancel_soon()
208+
else:
209+
print(
210+
"tractor ignores SIGINT while in debug mode\n"
211+
"If you have a special need for it please open an issue.\n"
212+
)
213+
214+
199215
@tractor.context
200216
async def _hijack_stdin_for_child(
201217

0 commit comments

Comments
 (0)