From a59fdfdd357dcdd4b22b0ca0e3d421e2a2d2d614 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 15 Jul 2019 20:17:10 +0300 Subject: [PATCH] stage: don't ignore SIGINT in the child (#2271) Signal mask is inherited by the child, so when we set it up before Popen, our child ignores SIGINT, which is wrong. What we should've done ideally, is to setup the signal handler after fork() but before exec(). That is pretty much what preexec_fn is used for in Popen, but unfortunately for us, it is not available on windows, so we can't use it. What we will do instead is just setup signal handler after Popen() but before communicate(), which would leave a slight gap where we might also get affected by SIGINTS meant for the child, but that is the best we can do. Signed-off-by: Ruslan Kuprieiev --- dvc/stage.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dvc/stage.py b/dvc/stage.py index 72367031f..ddf1e1342 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -775,9 +775,6 @@ class Stage(object): main_thread = isinstance( threading.current_thread(), threading._MainThread ) - if main_thread: - old_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) - p = None try: @@ -789,6 +786,8 @@ class Stage(object): executable=executable, close_fds=True, ) + if main_thread: + old_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) p.communicate() finally: if main_thread: