Skip to content

Commit

Permalink
fix: hot reloading broke because we did not restore the previous context
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Jun 24, 2023
1 parent aa282af commit 699c7e6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion solara/server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
reload.reloader.start()


class Local(threading.local):
app_context_stack: Optional[List[Optional["AppContext"]]] = None


local = Local()


class AppType(str, Enum):
SCRIPT = "script"
NOTEBOOK = "notebook"
Expand Down Expand Up @@ -270,12 +277,16 @@ def display(self, *args):
print(args) # noqa

def __enter__(self):
if local.app_context_stack is None:
local.app_context_stack = []
key = get_current_thread_key()
local.app_context_stack.append(current_context.get(key, None))
current_context[key] = self

def __exit__(self, *args):
key = get_current_thread_key()
current_context[key] = None
assert local.app_context_stack is not None
current_context[key] = local.app_context_stack.pop()

def close(self):
with self:
Expand Down

0 comments on commit 699c7e6

Please sign in to comment.