luminize
luminize

Reputation: 361

Python asynchronous/threads debugging in Visual Studio Code

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

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

Upvotes: 36

Views: 16382

Answers (2)

Maks
Maks

Reputation: 1639

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

Upvotes: 4

Set the debug to works with Visual Code.

You can see a good article about how you can set the debugger here and here, see:

The setting "stopOnEntry":true will cause the debugger to break at the first line of the python program being debugged. If this is not desired, then change the value from true to false. The default value of this setting is true.

Upvotes: 1

Related Questions