Skip to content

Commit

Permalink
fix: handling SIGINT correctly in reload.py, single entrance of block…
Browse files Browse the repository at this point in the history
…_thread in blocks.py (#8158)

* fix: handling SIGINT, single block_thread and fix popen

* Use pass

---------

Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
  • Loading branch information
2 people authored and dawoodkhan82 committed May 6, 2024
1 parent 0430f79 commit 8e0d09d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/cold-spies-fail.md
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:fix: handling SIGINT correctly in reload.py, single entrance of block_thread in blocks.py
19 changes: 11 additions & 8 deletions gradio/blocks.py
Expand Up @@ -2427,18 +2427,21 @@ def reverse(text):
}
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()

Expand Down
6 changes: 5 additions & 1 deletion gradio/cli/commands/reload.py
Expand Up @@ -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__":
Expand Down

0 comments on commit 8e0d09d

Please sign in to comment.