Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Hot reloading and rerunning app.run_server() don't work #106

Open
rohitsathish opened this issue Oct 19, 2022 · 3 comments
Open

Hot reloading and rerunning app.run_server() don't work #106

rohitsathish opened this issue Oct 19, 2022 · 3 comments

Comments

@rohitsathish
Copy link

The first time I run app.run_server(), it works fine and I am able to view the page.

However, hot reload doesn't work. I'm not sure of the expected behaviour so I tried the following:

  1. Reload cells with the code changes. No effect.
  2. Rerun the app.run_server() call. This causes the cell to run forever, with no changes on the page.

I've observed the same behaviour on both VSCode notebooks and JupyterLab.

@T4rk1n
Copy link
Contributor

T4rk1n commented Oct 19, 2022

Hi @rohitsathish , I think this is the same bug we've been trying to fix in #105. In the meantime, you can try installing older version of flask & werkzeug (<2.2.0).

@EvanCesanek
Copy link

Any update on this? I have the same issue in a VS Code notebook, forcing me to restart kernel to view any changes.

Seeing the work done in #105, I tried installing jupyter-dash from the latest on GitHub. With that version it no longer hangs when I call app.run_server() the second time, but I get the following error instead:

AssertionError: The setup method 'errorhandler' can no longer be called on the application. It has already handled its first request, any changes will not be applied consistently.
Make sure all imports, decorators, functions, etc. needed to set up the application are done before running it.

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In [2], line 1
----> 1 app.run_server(mode="inline", host="localhost")

File /opt/anaconda3/envs/envy/lib/python3.9/site-packages/jupyter_dash/jupyter_app.py:487, in JupyterDash.run_server(self, mode, width, height, inline_exceptions, **kwargs)
    482 def run_server(
    483         self,
    484         mode=None, width="100%", height=650, inline_exceptions=None,
    485         **kwargs
    486 ):
--> 487     self.run(
    488         mode=mode, width=width, height=height, inline_exceptions=inline_exceptions,
    489         **kwargs
    490     )

File /opt/anaconda3/envs/envy/lib/python3.9/site-packages/jupyter_dash/jupyter_app.py:284, in JupyterDash.run(self, mode, width, height, inline_exceptions, **kwargs)
    281         kwargs['dev_tools_hot_reload'] = mode == "external"
    283 # Set up custom callback exception handling
--> 284 self._config_callback_exception_handling(
    285     dev_tools_prune_errors=kwargs.get('dev_tools_prune_errors', True),
    286     inline_exceptions=inline_exceptions,
    287 )
    289 dev_tools_args = dict(
    290     debug=debug,
    291     dev_tools_ui=kwargs.pop("dev_tools_ui", None),
   (...)
    299     dev_tools_prune_errors=kwargs.pop("dev_tools_prune_errors", None),
    300 )
    302 if len(kwargs):

File /opt/anaconda3/envs/envy/lib/python3.9/site-packages/jupyter_dash/jupyter_app.py:431, in JupyterDash._config_callback_exception_handling(self, dev_tools_prune_errors, inline_exceptions)
    427 def _config_callback_exception_handling(
    428         self, dev_tools_prune_errors, inline_exceptions
    429 ):
--> 431     @self.server.errorhandler(Exception)
    432     def _wrap_errors(error):
    433         """Install traceback handling for callbacks"""
    434         self._traceback = sys.exc_info()[2]

File /opt/anaconda3/envs/envy/lib/python3.9/site-packages/flask/scaffold.py:49, in setupmethod.<locals>.wrapper_func(self, *args, **kwargs)
     48 def wrapper_func(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
---> 49     self._check_setup_finished(f_name)
     50     return f(self, *args, **kwargs)

File /opt/anaconda3/envs/envy/lib/python3.9/site-packages/flask/app.py:722, in Flask._check_setup_finished(self, f_name)
    720 def _check_setup_finished(self, f_name: str) -> None:
    721     if self._got_first_request:
--> 722         raise AssertionError(
    723             f"The setup method '{f_name}' can no longer be called"
    724             " on the application. It has already handled its first"
    725             " request, any changes will not be applied"
    726             " consistently.\n"
    727             "Make sure all imports, decorators, functions, etc."
    728             " needed to set up the application are done before"
    729             " running it."
    730         )

I also tried downgrading flask and werkzeug as suggested above, and it does allow me to run app.run_server() repeatedly with no error, but no HMR.

@mcstarioni
Copy link

It would be nice to use conda to exclude versions that are in conflict. For now, installation doesn't install flask<2.2.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants