Broken python breakpoints in thread C in pycharm or eclipse + pydev

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

I cannot set a breakpoint in python code, neither in PyDev nor in PyCharm. I also tried "gevent compatibility" without luck either.

I verified that callbacks are correctly called as logging.info resets the expected. Breakpoints set in other threads work fine. Thus, it seems that python debuggers cannot control breakpoints in python code caused by threads created in code other than python.

Does anyone know a workaround? Maybe there is some kind of "magic" thread initialization sequence that I could use?

+4
source share
2 answers

You need to configure the debugger mechanism to work on threads other than python (this is done automatically when creating a Python thread, but when you create a thread for which Python has no creation hook, you have to do it yourself) - note that for for some frameworks, such as QThread / Gevent, things are beheaded, so we know about initialization and run the debugger, but for other frameworks you have to do it yourself.

, :

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

, suspend=True, .

+6

@fabio-zadrozny.

, , ( C-) .

class TracingMixing(object):
    """The callbacks in the FUSE Filesystem are C threads and breakpoints don't work normally.
       This mixin adds callbacks to every function call so that we can breakpoint them."""

    def __call__(self, op, path, *args):
        pydevd.settrace(suspend=False, trace_only_current_thread=True, patch_multiprocessing=True)
        return getattr(self, op)(path, *args)
+2

Source: https://habr.com/ru/post/1620197/


All Articles