Skip to content

Commit

Permalink
Improval signal handling on windows #42
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-n committed Dec 26, 2022
1 parent 743569a commit 0641aec
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions poethepoet/executor/base.py
Expand Up @@ -212,10 +212,12 @@ def _exec_via_subproc(
proc = Popen(cmd, **popen_kwargs)

# signal pass through
def handle_signal(signum, _frame):
def handle_sigint(signum, _frame):
# sigint is not handled on windows
signum = signal.CTRL_C_EVENT if self._is_windows else signum
proc.send_signal(signum)

old_signal_handler = signal.signal(signal.SIGINT, handle_signal)
old_sigint_handler = signal.signal(signal.SIGINT, handle_sigint)

# send data to the subprocess and wait for it to finish
(captured_stdout, _) = proc.communicate(input)
Expand All @@ -224,7 +226,7 @@ def handle_signal(signum, _frame):
self.context.save_task_output(self.invocation, captured_stdout)

# restore signal handler
signal.signal(signal.SIGINT, old_signal_handler)
signal.signal(signal.SIGINT, old_sigint_handler)

return proc.returncode

Expand Down

0 comments on commit 0641aec

Please sign in to comment.