Skip to content

Commit 6e02a0f

Browse files
author
Edoardo Gallo
authored
Handle SIGHUP on Windows (#53)
* python on windows does not have SIGHUP - do not use lamba to not repeat the same def multiple times * check all signals * changelog
1 parent 7f033a1 commit 6e02a0f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
77
### Added
88
- Call `disconnect()` method.
99

10+
### Fixed
11+
- Check signals supported by the environment. On Windows there is no `SIGHUP`.
12+
1013
## [2.0.0rc1] - 2019-10-28
1114
### Added
1215
- Support for Calling `tap`, `tap_async` methods.

signalwire/relay/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,15 @@ async def cancel_pending_tasks(self):
112112
[task.cancel() for task in tasks]
113113
await asyncio.gather(*tasks, return_exceptions=True)
114114

115+
def handle_signal(self):
116+
asyncio.create_task(self.disconnect())
117+
115118
def attach_signals(self):
116-
for s in (signal.SIGHUP, signal.SIGTERM, signal.SIGINT):
117-
self.loop.add_signal_handler(s, lambda: asyncio.create_task(self.disconnect()))
119+
for s in ('SIGHUP', 'SIGTERM', 'SIGINT'):
120+
try:
121+
self.loop.add_signal_handler(getattr(signal, s), self.handle_signal)
122+
except:
123+
pass
118124

119125
async def on_socket_open(self):
120126
try:

0 commit comments

Comments
 (0)