fix: handling SIGINT correctly in reload.py, single entrance of block_thread in blocks.py (#8158)

* fix: handling SIGINT, single block_thread and fix popen

* Use pass

---------

Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
This commit is contained in:
Tiger3018 2024-05-03 01:58:25 +08:00 committed by GitHub
parent 2471f79527
commit 5671ff129a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 9 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
fix:fix: handling SIGINT correctly in reload.py, single entrance of block_thread in blocks.py

View File

@ -2427,18 +2427,21 @@ Received outputs:
}
analytics.launched_analytics(self, data)
# Block main thread if debug==True
if debug or int(os.getenv("GRADIO_DEBUG", "0")) == 1 and not wasm_utils.IS_WASM:
self.block_thread()
# Block main thread if running in a script to stop script from exiting
is_in_interactive_mode = bool(getattr(sys, "ps1", sys.flags.interactive))
# Block main thread if debug==True
if (
not prevent_thread_lock
and not is_in_interactive_mode
# In the Wasm env, we don't have to block the main thread because the server won't be shut down after the execution finishes.
# Moreover, we MUST NOT do it because there is only one thread in the Wasm env and blocking it will stop the subsequent code from running.
debug
or int(os.getenv("GRADIO_DEBUG", "0")) == 1
and not wasm_utils.IS_WASM
or (
# Block main thread if running in a script to stop script from exiting
not prevent_thread_lock
and not is_in_interactive_mode
# In the Wasm env, we don't have to block the main thread because the server won't be shut down after the execution finishes.
# Moreover, we MUST NOT do it because there is only one thread in the Wasm env and blocking it will stop the subsequent code from running.
and not wasm_utils.IS_WASM
)
):
self.block_thread()

View File

@ -126,7 +126,11 @@ def main(
GRADIO_WATCH_DEMO_PATH=str(path),
),
)
popen.wait()
if popen.poll() is None:
try:
popen.wait()
except (KeyboardInterrupt, OSError):
pass
if __name__ == "__main__":