In Pydev setting a breakpoint, but breakpoint not hit on callbacks only - python

Ok, I am new to python and my code calls some library (which is wrapping some C++ code) and I pass it a callback function on my side (as library needs to). The strange thing is that if I insert a breakpoint in my other part of the code, it will hit and deugger stops in eclipse but none of my breakpoints in the callback hit. The callback is sure called but the breakpoint is somehow ignored by PyDev. What I am doing wrong? The callback is obviously coming on a different thread. I am using Python 2.7

Try importing pdb and just manually setting breakpoints in the code with pdb.set_trace(). This won't work in all multi-threaded cases, but I find that it works in many of them and is a big improvement over the native Eclipse/PyDev debugger.

Related

Is it possible to debug commands executed inside the Python debugging console?

If I'm debugging a Python script in VS Code, while stopped at a breakpoint I have access to the Debugging Console, where I can execute Python code in the context of the current running interpreter/stack frame etc. Suppose in my code (the stuff in files, not the stuff I type in the console) I have a function function defined. I can call it from the debugging console by typing function(). However, if I have a breakpoint set inside function, VSCode does not stop at it.
Is there a way to achieve this behavior? The use case is for functions deep inside my codebase that I don't have a particularly convenient way to cause to be run by running any script. Rather than write a script that calls that function just so I have something to debug, sometimes I wish I could just start an interactive session (without even running a specific file), import and call my function interactively, and debug it from there.

Equivalent of pdb.runcall in Pycharm debugger

I use pdb.runcall to check if a function behaves as I expected. However, it does not have the visual component as IDE debuggers like Pycharm's. Can I do the same thing with Pycharm debugger without running the whole program from the beginning? I want to debug a specific function by using my current environment.
Apparently, we can attach a debugger to the console with a button on the console menu (green bug to the left of the console). If we place a breakpoint in the module or function we want to step into and call the function normally the debugger lands on the breakpoint like the normal debugger. But, with the console debugger, I was able to use the variables in my environment without running the whole application.

Is it possible to debug a method called from the interactive window in PTVS?

When I'm developing in Python I often want to debug a specific method, in which case it makes sense to call the method from the interactive console or debug interactive console. However, when a method is called from the interactive windows in PTVS, it doesn't stop at the break points in said method.
If it's possible, please tell me how to do it. If not, I would like to request this feature, and also to know if there is any quicker way to debug a specific method than calling it from the main script.
I'm using PTVS 2.0 RC in Visual Studio 2013 Ultimate
When using the regular (non-debug) Python Interactive window, you can actually attach VS to the python.exe process that it is running by using Debug -> Attach to Process. Once that is done, if the interactive window does something to e.g. hit a breakpoint, the debugger will hit on that breakpoint.
The tricky part is loading the code from a file in such a way that breakpoints are resolved. In particular, $load REPL command will not work because it just reads the file and evals it in the REPL line by line, without preserving the original file context. What you need is to load your script using Python facilities - e.g. import, or open+exec.
There are also some gotchas there - e.g. the REPL window will become unresponsive whenever you are paused on a breakpoint.

Debugging python gtk3 application

I'm writing a text editor in python and gtk3 and I keep getting vague warnings from somewhere within glib when I close a window:
/usr/lib/python2.7/dist-packages/gi/types.py:47: Warning: invalid (NULL) pointer instance
return info.invoke(*args, **kwargs)
How can I debug this? I tried running it in gdb, hoping I might be able to learn something from a breakpoint at g_logv, but the warnings appear without triggering the breakpoint. I can't easily replace the log handler either because of https://bugzilla.gnome.org/show_bug.cgi?id=670507.
I've even tried altering the python file referenced in the message so that it always prints a python backtrace at that point, but it has to do it whether the error occurs or not and it gets called on every gobject method call, so it's difficult to interpret the results, and it still doesn't tell me anything about which pointer is null.
If you want to use gdb, just run your script with the G_DEBUG environment variable set to "fatal-warnings" (G_DEBUG=fatal-warnings ./your-script.py). There is documentation in the Running GLib Applications section of the GLib manual.

Key bindings or workflow suggestions for managing breakpoints with pydbgr in Emacs 23.2

I have pydbgr working well now in Emacs 23.2 with virtualenv. But I am confused why breakpoints are not established from the source code buffer after running M-x pydbgr - as they would be e.g. when using pdb.
I tried invoking C-cC-b but this does not toggle breakpoints on the selected line as one would hope/expect.
Neither does C-xSPC work as it would in pdb.
When in the pydbgr shell window I can set breakpoints according to the first keyboard short-cut above, but it is naturally far more convenient to not have to move windows in order to do this.
Also, the left buffer margin intended for setting breakpoints via the mouse does not appear by default, and the MOUSE button binding for toggling normal and temporary breakpoints do not appear to work out-of-the-box, at least with my .emacs configuration.
I am using the latest pydbgr and dbgr.el code at the time of this posting.
Can anybody with experience of using pdbgr for debugging Python application please comment on the best approaches they have adopted in this regard. Perhaps some elisp configuration code to establish key-bindings that work from the source code windows. I noticed that pydbgr does not appear to invoke a minor/major-mode within the source buffer window, so I don't know where to start implementing this myself as I have no mode-hooks to hang elisp code off.
A recent change in emacs-dbgr on http://github.com/rocky/emacs-dbgr adds this. There are a number of other issues regarding breakpoint synchronization. emacs-dbgr is a work in progress, not a finished product.

Categories