Skip to content

Commit

Permalink
Make SIGINT handler kill the process tree
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
goodboy committed Aug 3, 2021
1 parent a105e32 commit 4b7502c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tractor/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,22 @@ async def _acquire_debug_lock(
log.debug(f"TTY lock released, remote task: {task_name}:{uid}")


def handler(signum, frame, *args):
"""Specialized debugger compatible SIGINT handler.
In childred we always ignore to avoid deadlocks since cancellation
should always be managed by the parent supervising actor. The root
is always cancelled on ctrl-c.
"""
if is_root_process():
tractor.current_actor().cancel_soon()
else:
print(
"tractor ignores SIGINT while in debug mode\n"
"If you have a special need for it please open an issue.\n"
)


@tractor.context
async def _hijack_stdin_for_child(

Expand Down

0 comments on commit 4b7502c

Please sign in to comment.