I'm using Visual Studio Code for writing my python application. Inspecting variables and things like setting a watch in the left debugging pane works OK if I write a simple synchronous one-file program.
However, I have code with classes in multiple files, and use various callbacks from other modules. Some which start a new thread.
One of those modules is canopen I can step thru my code, but when I enter the second line (below)
can0 = canopen.Network() can0.connect(channel='can0', bustype='socketcan')
then the call stack changes from:
CALL STACK paused on breakpoint main <module>
to
CALL STACK paused on breakpoint MainThread Thread#15034.........
and simultaneously
and the watches in my watch window shows:
can0: not available
How can I (setup VS studio code with Python to) inspect/debug my python code with various threads and code in various files?
Regards, Bas
Yes. In the Threads window (Debug -> Windows -> Threads) right-click the thread you want and select "switch to thread". You can also choose "freeze" on the threads you don't want to debug in order to keep them from running. Don't forget to "thaw" them if you expect them to do work, however.
Debug asynchronous code Debugging asynchronous code is a challenge because the tasks are often scheduled in one thread and executed in another. Every thread has its own stacktrace, making it difficult to figure out what happened before the thread started.
Python in Visual Studio supports debugging without a project. With a stand-alone Python file open, right-click in the editor, select Start with Debugging, and Visual Studio launches the script with the global default environment (see Python environments) and no arguments.
To display the Threads window in break mode or run mode While Visual Studio is in debug mode, select the Debug menu, point to Windows, and then select Threads.
New debugger is capable of debugging async applications. Check out how to set it up How to update ptvsd used by Visual Studio Code in debug mode And don't forget to add "subProcess": true, in launch.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With