mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
replace exception catch with signal
This commit is contained in:
+4
-4
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user