fix: Ctrl+C not terminating backend on Linux (#4316)
* fix: Ctrl+C not breaking out of backend on Linux threading.Event.wait() without a timeout blocks at the C level on Linux, preventing Python from delivering SIGINT. Use a 1-second timeout loop so the interpreter can process pending signals. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
164b5a5b06
commit
08b5879101
2 changed files with 10 additions and 3 deletions
|
|
@ -144,7 +144,10 @@ def studio_default(
|
|||
|
||||
try:
|
||||
if _shutdown_event is not None:
|
||||
_shutdown_event.wait()
|
||||
# NOTE: Event.wait() without a timeout blocks at the C level
|
||||
# on Linux, preventing Python from delivering SIGINT (Ctrl+C).
|
||||
while not _shutdown_event.is_set():
|
||||
_shutdown_event.wait(timeout = 1)
|
||||
else:
|
||||
while True:
|
||||
time.sleep(1)
|
||||
|
|
|
|||
|
|
@ -270,5 +270,9 @@ if __name__ == "__main__":
|
|||
if hasattr(signal, "SIGBREAK"):
|
||||
signal.signal(signal.SIGBREAK, _signal_handler)
|
||||
|
||||
# Keep running until shutdown signal
|
||||
_shutdown_event.wait()
|
||||
# Keep running until shutdown signal.
|
||||
# NOTE: Event.wait() without a timeout blocks at the C level on Linux,
|
||||
# which prevents Python from delivering SIGINT (Ctrl+C). Using a
|
||||
# short timeout in a loop lets the interpreter process pending signals.
|
||||
while not _shutdown_event.is_set():
|
||||
_shutdown_event.wait(timeout = 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue