Not working python breakpoints in C thread in pycharm or eclipse+pydev

后端 未结 2 883
一个人的身影
一个人的身影 2020-12-16 04:46

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 brea

2条回答
  •  别那么骄傲
    2020-12-16 05:44

    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.

提交回复
热议问题