Skip to content

Commit

Permalink
Merge pull request #8 from digital-asset/python-optional-sigint-handler
Browse files Browse the repository at this point in the history
python: Make both SIGINT and SIGQUIT handlers optional.
  • Loading branch information
da-tanabe authored Jun 12, 2019
2 parents 902bbb3 + f73be11 commit 72b000d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.6.4
5.6.5
14 changes: 7 additions & 7 deletions python/dazl/client/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ def start_in_background(
run_state = RunState(RunLevel.RUN_FOREVER)
if install_signal_handlers:
# the main loop will be run from a background thread, so do NOT use asyncio directly
signal.signal(signal.SIGINT, lambda *_: self._impl.shutdown())
try:
signal.signal(signal.SIGINT, lambda *_: self._impl.abort())
except ValueError:
# SIGQUIT is not supported on Windows.
signal.signal(signal.SIGINT, lambda *_: self._impl.shutdown())
signal.signal(signal.SIGQUIT, lambda *_: self._impl.abort())
except (NotImplementedError, AttributeError, ValueError):
# SIGINIT and SIGQUIT handlers are not supported on Windows.
pass

return self._impl.start(run_state, daemon)
Expand Down Expand Up @@ -259,11 +259,11 @@ def _run(self, initial_run_level, *coroutines: Awaitable[None],
run_state = RunState(initial_run_level)
loop = get_event_loop()
if install_signal_handlers:
loop.add_signal_handler(signal.SIGINT, run_state.handle_sigint)
try:
loop.add_signal_handler(signal.SIGINT, run_state.handle_sigint)
loop.add_signal_handler(signal.SIGQUIT, run_state.handle_sigquit)
except ValueError:
# SIGQUIT is not supported on Windows.
except (NotImplementedError, AttributeError, ValueError):
# SIGINT and SIGQUIT are not supported on Windows.
pass

loop.run_until_complete(self.aio_run(*coroutines, run_state=run_state))
Expand Down
9 changes: 6 additions & 3 deletions python/dazl/util/termcap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
from typing import Optional, Tuple


def termsize() -> Tuple[Optional[int], Optional[int]]:
def termsize() -> 'Tuple[Optional[int], Optional[int]]':
"""
Return the current size of the terminal. If the current terminal is not a tty, then
``(None, None)`` is returned.
"""
with Popen(['stty', 'size'], stdout=PIPE, stderr=DEVNULL) as proc:
term_size_str = proc.stdout.read().decode('utf8')
try:
with Popen(['stty', 'size'], stdout=PIPE, stderr=DEVNULL) as proc:
term_size_str = proc.stdout.read().decode('utf8')
except FileNotFoundError:
term_size_str = None
if term_size_str is not None:
dimensions = term_size_str.split()
if len(dimensions) >= 2:
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dazl"
version = "5.6.4"
version = "5.6.5"
description = "high-level Ledger API client for DAML ledgers"
license = "Apache-2.0"
authors = ["Davin K. Tanabe <davin.tanabe@digitalasset.com>"]
Expand Down

0 comments on commit 72b000d

Please sign in to comment.