Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 6f91450

Browse files
NickCaogithub-actions[bot]
authored andcommitted
Add signal_handler helper method
(cherry picked from commit 8c7b1b0)
1 parent bc2d451 commit 6f91450

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

  • packages/jumpstarter-cli-common/jumpstarter_cli_common
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import signal
2+
3+
import asyncclick as click
4+
from anyio import open_signal_receiver
5+
from anyio.abc import CancelScope
6+
7+
8+
# Reference: https://github.com/agronholm/anyio/blob/4.9.0/docs/signals.rst
9+
async def signal_handler(scope: CancelScope):
10+
with open_signal_receiver(signal.SIGINT, signal.SIGTERM) as signals:
11+
async for signum in signals:
12+
match signum:
13+
case signal.SIGINT:
14+
click.echo("SIGINT pressed, terminating", err=True)
15+
case signal.SIGTERM:
16+
click.echo("SIGTERM received, terminating", err=True)
17+
case _:
18+
pass
19+
20+
scope.cancel()
21+
22+
break

0 commit comments

Comments
 (0)