Skip to content

Commit 3debf50

Browse files
authored
Merge pull request #24 from MKLeb/hotfix/no-signal-handling-on-windows
Catch NotImplementedError on loop.add_signal_handler for Windows
2 parents fee3dee + ea3a317 commit 3debf50

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

changelog/24.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Catch `NotImplementedError` exception when setting up signal handling. Windows, for example, does not support signal handling with asyncio.

src/ptscripts/process.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,11 @@ async def _subprocess_run(
231231
loop = asyncio.get_running_loop()
232232
for signame in ("SIGINT", "SIGTERM"):
233233
sig = getattr(signal, signame)
234-
loop.add_signal_handler(sig, partial(_handle_signal, proc, sig))
234+
try:
235+
loop.add_signal_handler(sig, partial(_handle_signal, proc, sig))
236+
except NotImplementedError:
237+
# On Windows, `add_signal_handler` is not defined, so we catch and ignore
238+
pass
235239
stdout, stderr = await asyncio.shield(proc.communicate())
236240
result = subprocess.CompletedProcess(
237241
args=cmdline,

0 commit comments

Comments
 (0)