如何解决Jupyter / Tornado“ DeprecationWarning:`should_run_async`将来不会自动调用`transform_cell`”
我有一个非常简单的iPython笔记本my_nb.ipynb
,其中有两个简单的单元格
from mcmc import Tree
a = Tree()
print(a)
该代码曾经运行时没有问题,但最近在Jupyter中运行时已停止运行(当然,mcmc.py
中的代码未更改)。当我使用ipython my_nb.ipynb
运行此代码时,脚本可以正常运行并且完成而没有错误。但是,当我在Jupyter中打开笔记本电脑时,第一个单元运行正常,但是第二个单元停滞不前,并且永远不会完成,并且控制台显示以下错误(或警告):
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 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.
也许更令人困惑的是,如果我将所有代码放在笔记本中的单个单元格中,那么整个代码在Jupyter的命令行和中都将正确无误地完成。
我已经检查过this similar thread,但我的ipykernel已更新。实际上,我认为所有相关库都是最新版本:
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
任何帮助,将不胜感激!
解决方法
有机会在代码中的某个位置碰巧出现'warnings.filterwarnings(“ error”)'或类似行吗?
我只是在今天遇到了同样的情况,最终将问题追溯到我的自定义程序包中使用的这一行代码。一旦我在代码中注释了这一行,这个Jupyter挂起的问题就消失了。
在故障排除期间,我看到了这个问题,所以我认为我应该写下这些信息,以防其他人可能从中受益。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。