【问题标题】:Why is Pycharm debugger not stopping at a breakpoint outside the main thread? [duplicate]为什么 Pycharm 调试器不在主线程外的断点处停止? [复制]
【发布时间】:2017-03-08 14:07:03
【问题描述】:

我正在使用 PyCharm 2016.2.3(内部版本 #PY-162.1967.10)。无论断点的挂起属性是全部还是线程,我都无法让调试器在主线程外的任何断点处停止;或者如果这是整个程序中唯一的断点。线程是通过移动到 QThread 中的 QObject 来实现的。这是一个显示问题的简单代码。辅助线程中的任何位置(Master.do() 或 Worker.run() 内部)的断点都不会被命中。

import sys
from PyQt5.QtCore import QCoreApplication, QObject, QThread, pyqtSignal, pyqtSlot


class Worker(QObject):
    """
    Generic worker.
    """
    start = pyqtSignal(str)
    finished = pyqtSignal()

    def __init__(self, function):
        QObject.__init__(self)
        self._function = function
        self.start.connect(self.run)

    @pyqtSlot()
    def run(self):
        #TODO Breakpoints inside this method will not be hit.
        self._function()
        self.finished.emit()


class Master(QObject):
    """
    An object that will use the worker class.
    """

    def __init__(self):
        QObject.__init__(self)

    def do(self):
        #TODO Breakpoints inside this method will not be hit.
        print("All done.")
        QCoreApplication.quit()


def main():
    app = QCoreApplication(sys.argv)

    master = Master()
    worker = Worker(master.do)

    thread = QThread()
    worker.moveToThread(thread)
    thread.started.connect(worker.run)

    # Terminating thread gracefully, or so.
    worker.finished.connect(thread.quit)
    worker.finished.connect(worker.deleteLater)
    thread.finished.connect(thread.deleteLater)

    thread.start()

    sys.exit(app.exec_())


if __name__ == "__main__":
    main()

【问题讨论】:

    标签: multithreading debugging pyqt pycharm breakpoints


    【解决方案1】:

    在这里找到答案:Not working python breakpoints in C thread in pycharm or eclipse+pydev

    基本上,我必须导入 pydevd 并在启动后立即在线程中添加以下内容: pydevd.settrace(suspend=False, trace_only_current_thread=True)

    【讨论】:

      猜你喜欢
      • 2015-02-08
      • 2014-04-12
      • 2021-07-21
      • 1970-01-01
      • 2020-08-31
      • 2016-11-19
      • 2023-03-12
      • 2023-03-15
      • 1970-01-01
      相关资源
      最近更新 更多