Fixes Blocks exit issue (#3600)

* fix

* changelog

* blocks

* formatting
This commit is contained in:
Abubakar Abid 2023-03-24 09:48:32 -07:00 committed by GitHub
parent 9d3f58b898
commit 7a4e22b61a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 0 deletions

View File

@ -10,6 +10,7 @@
- Fixed bug where text for altair plots was not legible in dark mode by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3555](https://github.com/gradio-app/gradio/pull/3555)
- Fixes `Chatbot` and `Image` components so that files passed during processing are added to a directory where they can be served from, by [@abidlabs](https://github.com/abidlabs) in [PR 3523](https://github.com/gradio-app/gradio/pull/3523)
- Fixes an an issue where if the Blocks scope was not exited, then State could be shared across sessions, by [@abidlabs](https://github.com/abidlabs) in [PR 3600](https://github.com/gradio-app/gradio/pull/3600)
- Fixed bug where "or" was not being localized in file upload text by [@freddyaboulton](https://github.com/freddyaboulton) in [PR 3599](https://github.com/gradio-app/gradio/pull/3599)
## Documentation Changes:

View File

@ -1149,6 +1149,7 @@ class Blocks(BlockContext):
Context.root_block = self
self.parent = Context.block
Context.block = self
self.exited = False
return self
def __exit__(self, *args):
@ -1163,6 +1164,7 @@ class Blocks(BlockContext):
self.config = self.get_config_file()
self.app = routes.App.create_app(self)
self.progress_tracking = any(block_fn.tracks_progress for block_fn in self.fns)
self.exited = True
@class_or_instancemethod
def load(
@ -1384,6 +1386,9 @@ class Blocks(BlockContext):
demo = gr.Interface(reverse, "text", "text")
demo.launch(share=True, auth=("username", "password"))
"""
if not self.exited:
self.__exit__()
self.dev_mode = False
if (
auth

View File

@ -8,6 +8,7 @@ import random
import sys
import time
import unittest.mock as mock
import uuid
import warnings
from contextlib import contextmanager
from functools import partial
@ -393,6 +394,12 @@ class TestBlocksMethods:
with gr.Blocks(theme="freddyaboulton/this-theme-does-not-exist") as demo:
assert demo.theme.to_dict() == gr.themes.Default().to_dict()
def test_exit_called_at_launch(self):
with gr.Blocks() as demo:
gr.Textbox(uuid.uuid4)
demo.launch(prevent_thread_lock=True)
assert len(demo.get_config_file()["dependencies"]) == 1
class TestComponentsInBlocks:
def test_slider_random_value_config(self):