在pycharm或eclipse + pydev中的C线程中不工作python断点 [英] Not working python breakpoints in C thread in pycharm or eclipse+pydev

查看:237
本文介绍了在pycharm或eclipse + pydev中的C线程中不工作python断点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个django应用程序使用C ++库(通过swig导入)。
C ++库启动自己的线程,它调用Python代码中的回调函数。



我不能在python代码中设置断点,也不能在PyDev或PyCharm中设置断点。
也尝试'gevent兼容性'选项,没有运气。



我验证了回调被正确调用为logging.info转储了什么预期。在其他线程中设置的断点工作正常。所以似乎python调试器无法管理在非python代码中创建的线程所调用的python代码中的断点。



有人知道解决方法吗?也许有一些我可以使用的魔术线程初始化序列?

解决方案

你必须设置调试器机器才能工作在非python线程上(当Python线程被创建时,这是自动完成的,但是当您创建一个Python没有任何创建钩子的线程时,您必须自己做) - 请注意,对于某些框架 - 例如QThread / Gevent - 事情是猴子打补丁,所以我们知道初始化和启动调试器,但对于其他框架,你必须自己做。



这样做后,你必须调用线程:

  import pydevd 
pydevd.settrace(suspend = False, trace_only_current_thread = True)

请注意,如果您将 suspend = True ,它会模拟一个手动断点,并在代码的那一点停止。


I have a django application using a C++ library (imported via swig). The C++ library launches own thread which calls callbacks in Python code.

I cannot setup a breakpoint in python code, neither in PyDev nor PyCharm. Tried also 'gevent compatibility' option too with no luck.

I verified the callbacks are properly called as logging.info dumps what expected. Breakpoints set in other threads work fine. So it seems that python debuggers cannot manage breakpoints in python code called by threads created in non-python code.

Does anyone know a workaround? Maybe there is some 'magic' thread initialization sequence I could use?

解决方案

You have to setup the debugger machinery for it to work on non-python threads (this is done automatically when a Python thread is created, but when you create a thread for which Python doesn't have any creation hook, you have to do it yourself) -- note that for some frameworks -- such as QThread/Gevent -- things are monkey patched so that we know about the initialization and start the debugger, but for other frameworks you have to do it yourself.

To do that, after starting the thread you have to call:

import pydevd
pydevd.settrace(suspend=False, trace_only_current_thread=True)

Note that if you had put suspend=True, it'd simulate a manual breakpoint and would stop at that point of the code.

这篇关于在pycharm或eclipse + pydev中的C线程中不工作python断点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆