Skip to content

Commit c1a93a8

Browse files
authored
Add terminated by signal ctrl+c support (#140)
Co-authored-by: DESKTOP\atthaboon.s <atthaboon.s@qahive.com>
1 parent 56974a2 commit c1a93a8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

PuppeteerLibrary/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from robot.api.deco import not_keyword
1111
from robot.api import logger
1212
from robot.libraries.BuiltIn import BuiltIn
13+
from robot.errors import ExecutionFailed
1314
from pyppeteer.browser import Browser
1415
from PuppeteerLibrary.library_context.ilibrary_context import iLibraryContext
1516
from PuppeteerLibrary.library_context.library_context_factory import LibraryContextFactory
@@ -120,7 +121,7 @@ def __init__(self, disable_python_logging=True):
120121
try:
121122
signal.signal(signal.SIGINT, self.terminal_signal_handler)
122123
except:
123-
print('Warning: Not handle ternial signal')
124+
print('Warning: Not handle terminal signal')
124125

125126
try:
126127
self.loop = asyncio.get_event_loop()
@@ -215,7 +216,7 @@ def failure_occurred(self):
215216
def terminal_signal_handler(self, sig, frame):
216217
print('You pressed Ctrl+C!')
217218
BuiltIn().run_keyword_and_ignore_error('Close Puppeteer')
218-
sys.exit(0)
219+
self._stop_execution_gracefully()
219220

220221
def _disable_python_logging(self):
221222
# Force node not throw any unhandled task
@@ -226,6 +227,9 @@ def _disable_python_logging(self):
226227
logging.disable(logging.CRITICAL)
227228
logging.warning('Protocol problem:')
228229

230+
def _stop_execution_gracefully(self):
231+
raise ExecutionFailed('Execution terminated by signal', exit=True)
232+
229233
from ._version import get_versions
230234
__version__ = get_versions()['version']
231235
del get_versions

0 commit comments

Comments
 (0)