Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block close rightly. #8357

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/petite-plants-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:block close rightly.
13 changes: 8 additions & 5 deletions gradio/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2616,13 +2616,16 @@ def block_thread(
"""Block main thread until interrupted by user."""
try:
while True:
time.sleep(0.1)
if self.is_running:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @DoiiarX ! Can you please provide some more information about what this is solving? I can close running gradio applications with ctrl + C with the code as it is.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind just saw the linked issue. Will take a look.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok took a look and I'm still confused. When I run the linked code, the server does not restart.

image

Starting gradio outside the main thread is not really possible because the asyncio event loop is only started in the main thread. So I think it does not make sense to support this use case.

time.sleep(0.1)
else:
break
except (KeyboardInterrupt, OSError):
print("Keyboard interruption in main thread... closing server.")
if self.server:
self.server.close()
for tunnel in CURRENT_TUNNELS:
tunnel.kill()
if self.server:
self.server.close()
for tunnel in CURRENT_TUNNELS:
tunnel.kill()

def attach_load_events(self):
"""Add a load event for every component whose initial value should be randomized."""
Expand Down