Search code examples
python-3.xjupyter-notebookipythonjupytertornado

Jupyter / Tornado "DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future"


I have a very simple iPython notebook my_nb.ipynb with two simple cells

from mcmc import Tree
a = Tree()
print(a)

This code used to run without problems, but recently has stopped functioning when I run it in Jupyter (and, of course, the code in mcmc.py has not changed). When I run this code with ipython my_nb.ipynb the script runs fine and finishes without error. However, when I open the notebook in Jupyter, the first cell runs fine but the second stalls and never finishes, and the console shows the following error (or warning, really):

Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/ipykernel/kernelbase.py", line 268, in dispatch_shell
    yield gen.maybe_future(handler(stream, idents, msg))
  File "/usr/lib/python3.8/site-packages/tornado/gen.py", line 735, in run
    value = future.result()
  File "/usr/lib/python3.8/site-packages/tornado/gen.py", line 742, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "/usr/lib/python3.8/site-packages/ipykernel/kernelbase.py", line 542, in execute_request
    reply_content = yield gen.maybe_future(
  File "/usr/lib/python3.8/site-packages/tornado/gen.py", line 735, in run
    value = future.result()
  File "/usr/lib/python3.8/site-packages/tornado/gen.py", line 209, in wrapper
    yielded = next(result)
  File "/usr/lib/python3.8/site-packages/ipykernel/ipkernel.py", line 287, in do_execute
    and should_run_async(code)
  File "/usr/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 2954, in should_run_async
    warnings.warn(
DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.

Perhaps even more puzzling, if I put all the code in a single cell in the notebook, then the whole code finishes without error both in the command line and in Jupyter.

I have checked this similar thread but my ipykernel is already up to date. In fact, I think all relevant libraries are all at their most current versions:

jupyter core     : 4.6.3
jupyter-notebook : 6.1.4
qtconsole        : not installed
ipython          : 7.18.1
ipykernel        : 5.3.4
jupyter client   : 6.1.6
jupyter lab      : 2.2.7
nbconvert        : 5.6.1
ipywidgets       : 7.5.1
nbformat         : 5.0.6
traitlets        : 4.3.3
tornado          : 6.0.4-2
terminado        : 0.8.3-1

Any help with this will be much appreciated!


Solution

  • By any chance, do you happen to have 'warnings.filterwarnings("error")' or a similar line somewhere in your code?

    I just bumped into the same situation just today and have finally traced the problem to this line of code, which was used in my custom package. Once I comment this line out in my code, this Jupyter hanging problem disappeared.

    During troubleshooting, I saw this question, so I thought I should write this information down just in case somebody else may benefit from this.