python - 试图设置 ipdb.set_trace(): RuntimeError: There is no current event loop in thread 'Thread-....'
问题描述
我在 Windows 7 上使用 Miniconda 3,试图ipdb
在我的程序中启动调试过程。我已经安装了 IPython ipdb
,当然还有(在 virtualenv 中)。
测试程序:
#!/usr/bin/env python
import ipdb
def a():
for i in range(10):
print(i)
ipdb.set_trace()
print(100)
a()
我得到的是 Python 开始进入无限循环,一遍又一遍地喷出这样的异常:
Exception in thread Thread-3398:
Traceback (most recent call last):
File "C:\ACME\Dev\Miniconda3\lib\threading.py", line 926, in _bootstrap_inner
self.run()
File "C:\ACME\Dev\Miniconda3\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:\ACME\Dev\projects\example\venv\lib\site-packages\IPython\terminal\debugger.py", line 102, in in_thread
line = self.pt_app.prompt()
File "C:\ACME\Dev\projects\example\venv\lib\site-packages\prompt_toolkit\shortcuts\prompt.py", line 992, in prompt
return get_event_loop().run_until_complete(self._dumb_prompt(self.message))
File "C:\ACME\Dev\Miniconda3\lib\asyncio\events.py", line 644, in get_event_loop
% threading.current_thread().name)
RuntimeError: There is no current event loop in thread 'Thread-3398'.
这可能是什么原因以及如何解决这个问题?
版本:
Python 3.7.6
ipdb==0.13.3
ipykernel==5.3.0
ipython==7.15.0
ipython-genutils==0.2.0
ipywidgets==7.5.1
(我列出了我发现的与 IPython 相关的所有软件包,如果重要的话,我还安装了 Jupyter)。
解决方案
我用新的代码片段替换了旧样式
import ipdb;
ipdb.set_trace()
例如:
from IPython.core import debugger
debug = debugger.Pdb().set_trace
def buggy_method():
debug()
我解决了这个问题。请参阅https://github.com/ipython/ipython/pull/9731/上的参考资料
推荐阅读
- html - 如何在危险的SetInnerHTML中设置默认值?
- azure - Azure 静态网站 - 在 Chrome 中显示旧内容
- java - Java Spring Test Autowired Controller 为空错误
- python - 无法在 Django 中显示静态图像和加载 CSS
- python - 在pyqt中使用sceneEventFilter捕获悬停事件
- api - WSO2 ESB 返回一串 json 结构
- flutter - Sliver Appbar [Collapsing Toolbar] 在 Flutter 中从左到中动画标题
- numpy - 许多矩阵乘积的数值稳定性
- git - Git Blame 在一个开发人员项目中......如何获取分支和评论而不是作者姓名?
- asp.net - 提交后重置输入字段