Skip to content

Commit

Permalink
replace exception catch with signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill Vasin committed Jun 20, 2019
1 parent ccb8e33 commit 5457c16
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 4 additions & 4 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import subprocess
import logging
import signal

from dvc.utils import relpath
from dvc.utils.compat import pathlib
Expand Down Expand Up @@ -775,10 +776,9 @@ def _run(self):
executable=executable,
)

try:
p.communicate()
except KeyboardInterrupt:
p.communicate()
signal.signal(signal.SIGINT, signal.SIG_IGN)
p.communicate()
signal.signal(signal.SIGINT, signal.default_int_handler)

if p.returncode != 0:
raise StageCmdFailedError(self)
Expand Down
7 changes: 6 additions & 1 deletion tests/func/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,15 @@ def test_run_args_with_spaces(self):
self.assertEqual(stage.cmd, 'echo "foo bar"')

@mock.patch.object(subprocess, "Popen", side_effect=KeyboardInterrupt)
def test_keyboard_interrupt(self, _):
def test_keyboard_interrupt_before_communicate(self, _):
ret = main(["run", "mycmd"])
self.assertEqual(ret, 252)

@mock.patch.object(subprocess.Popen, "wait", new=KeyboardInterrupt)
def test_keyboard_interrupt_during_communicate(self):
ret = main(["run", "python", "code.py"])
self.assertEqual(ret, 1)


class TestRunRemoveOuts(TestDvc):
def test(self):
Expand Down

0 comments on commit 5457c16

Please sign in to comment.