File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change 1414
1515from __future__ import annotations
1616
17+ import enum
1718import select
1819import signal
1920import socket
2223from types import FrameType
2324from typing import Any
2425
25- type SignalCallback = Callable [[signal .Signals ], Any ]
26+ type SignalCallback = Callable [[signal .Signals | SpecialExit ], Any ]
2627type StartStopCall = Callable [[], Any ]
2728type _HANDLER = Callable [[int , FrameType | None ], Any ] | int | signal .Handlers | None
2829
3233actual = tuple (e for name , e in signal .Signals .__members__ .items () if name in possible )
3334
3435
36+ class SpecialExit (enum .IntEnum ):
37+ EXIT = 252
38+
39+
3540class SignalService :
3641 """Meant for graceful signal handling where the main thread is only used for signal handling.
3742 This should be paired with event loops being run in threads."""
@@ -74,9 +79,10 @@ def run(self):
7479
7580 select .select ([self .ss ], [], [])
7681 data , * _ = self .ss .recv (4096 )
82+ sig = signal .Signals (data ) if data != 252 else SpecialExit .EXIT
7783
7884 for cb in self ._cbs :
79- cb (signal . Signals ( data ) )
85+ cb (sig )
8086
8187 for join in self ._joins :
8288 join ()
You can’t perform that action at this time.
0 commit comments