Visual Studio Code 中的 Python 异步/线程调试

标签 python multithreading debugging visual-studio-code

我正在使用 Visual Studio Code 编写我的 python 应用程序。如果我编写一个简单的同步单文件程序,检查变量和在左侧调试 Pane 中设置监视之类的东西可以正常工作。

但是,我在多个文件中有包含类的代码,并使用来自其他模块的各种回调。一些开始一个新线程。

其中一个模块是 canopen
我可以单步执行我的代码,但是当我输入第二行时(如下)

can0 = canopen.Network()
can0.connect(channel='can0', bustype='socketcan')

然后调用堆栈从:
CALL STACK paused on breakpoint
main
<module>


CALL STACK paused on breakpoint
MainThread
Thread#15034.........

并且同时
  • 变量 Pane 清除
  • 我的 watch 窗口中的 watch 显示:
    can0: not available

  • 我如何(使用 Python 设置 VS Studio 代码)使用各种线程和各种文件中的代码检查/调试我的 Python 代码?

    问候,
    巴斯

    最佳答案

    新的调试器能够调试异步应用程序。
    查看如何设置
    How to update ptvsd used by Visual Studio Code in debug mode
    并且不要忘记在launch.json中添加“subProcess”:true

    关于Visual Studio Code 中的 Python 异步/线程调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43569165/

    相关文章:

    python - 我们如何在 Python 中有效地检查字符串是否为十六进制

    python - 在列上执行 .astype 'b' ) 时,Pandas to_csv 前缀 ('|S'

    Python:如何使用函数通过理解来定义二维数组?

    c++ - 为什么win api线程执行函数,而标准线程不执行?

    c++ - memory_order_seq_cst 如何与非原子操作同步?

    svn - 集成了Visual SVN和错误跟踪

    python - 如何有效地从多个列表中获取一组唯一值 (Python)

    c# - 由于挂起的数据库调用而取消线程

    javascript - 查看 html 节点上的所有打开事件 - Javascript

    javascript - 隐藏 getter 或添加到 proto 对象中