replace exception catch with signal

This commit is contained in:
Kirill Vasin
2019-06-20 13:39:22 +03:00
parent ccb8e338e1
commit 5457c16e76
2 changed files with 10 additions and 5 deletions
+4 -4
View File
@@ -7,6 +7,7 @@ import re
import os
import subprocess
import logging
import signal
from dvc.utils import relpath
from dvc.utils.compat import pathlib
@@ -775,10 +776,9 @@ class Stage(object):
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)
+6 -1
View File
@@ -324,10 +324,15 @@ class TestCmdRun(TestDvc):
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):