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

Fix address warnings on kernel initialized dispatch #205

32 changes: 18 additions & 14 deletions solara/server/patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,38 @@ def set_custom_exc(self, exc_tuple, handler):
pass


kernel_instance_dispatch_initial = ipykernel.kernelbase.Kernel.instance.__func__
Kernel_instance_original = ipykernel.kernelbase.Kernel.instance.__func__ # type: ignore


def kernel_instance_dispatch(cls, *args, **kwargs):
if not app.has_current_context():
return kernel_instance_dispatch_initial(cls, *args, **kwargs)
else:
if app.has_current_context():
context = app.get_current_context()
return context.kernel
else:
return Kernel_instance_original(cls, *args, **kwargs)


Kernel_initialized_initial = ipykernel.kernelbase.Kernel.initialized.__func__ # type: ignore


InteractiveShell_instance_initial = InteractiveShell.instance
def kernel_initialized_dispatch(cls):
if app is None: # python is shutting down, and the comm dtor wants to send a close message
return False
if app.has_current_context():
return True
else:
return Kernel_initialized_initial(cls)


InteractiveShell_instance_initial = InteractiveShell.instance.__func__ # type: ignore


def interactive_shell_instance_dispatch(cls, *args, **kwargs):
if app.has_current_context():
context = app.get_current_context()
return context.kernel.shell
else:
return InteractiveShell_instance_initial(*args, **kwargs)


def kernel_initialized_dispatch(cls):
try:
app.get_current_context()
except RuntimeError:
return False
return True
return InteractiveShell_instance_initial(cls, *args, **kwargs)


def display_solara(
Expand Down