jupyter-dash icon indicating copy to clipboard operation
jupyter-dash copied to clipboard

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

Open rohitsathish opened this issue 3 years ago • 3 comments

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.

rohitsathish avatar Oct 19 '22 08:10 rohitsathish

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).

T4rk1n avatar Oct 19 '22 13:10 T4rk1n

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.

EvanCesanek avatar Dec 02 '22 22:12 EvanCesanek

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

mcstarioni avatar Mar 01 '23 18:03 mcstarioni