Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when use QThread Debug PyQt app, breakpoint not work,while wing IDE can debug #176

Closed
DonJayamanne opened this issue Nov 14, 2017 · 7 comments
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster

Comments

@DonJayamanne
Copy link

From @xystar2012 on September 13, 2017 6:14

Environment data

VS Code version: 1.15.1
Python Extension version:3.5
Python Version:python3.5
OS and version: win7 x64

Actual behavior

make breakpoint in the Qthread run function,I'm not able to place a debug break in the run method.

Expected behavior

stop at the breakpoint in Qthread run method,as the breakpoints mainthread can do

Steps to reproduce:

Logs

Output from Python output panel

Output from Console window (Help->Developer Tools menu)

no output at all

Copied from original issue: DonJayamanne/pythonVSCode#1209

@DonJayamanne DonJayamanne added Debugger and removed m labels Nov 14, 2017
@brettcannon brettcannon added awaiting 1-verification area-debugging bug Issue identified by VS Code Team member as probable bug labels Nov 14, 2017
@DonJayamanne
Copy link
Author

@xystar2012 Please could you provide some sample code used to replicate this issue.

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed awaiting 1-verification labels Jan 11, 2018
@brettcannon
Copy link
Member

Due to over a month of inactivity after asking for more info, I'm closing this issue. If you are able to provide the requested information in the future we will be happy to open this issue again.

@ChrisK91
Copy link

I've come across the same issue. Only relevant package is PyQt5. Here is some code to reproduce the issue.

Steps to reproduce:

  1. Insert breakpoint on line 16, 18 or 19
  2. Run the program and press the button
  3. Observe, that the message is changed from inside the thread

Actual behaviour: no breakpoint is hit
Expected behaviour: breakpoints should be hit

Note: Code has been adapted from https://stackoverflow.com/questions/41526832/pyqt5-qthread-signal-not-working-gui-freeze

import time
import sys

from PyQt5.QtCore import QObject, QThread, pyqtSignal, pyqtSlot
from PyQt5.QtWidgets import QApplication, QPushButton, QTextEdit, QVBoxLayout, QWidget, QLabel


class Worker(QObject):
    sig_msg = pyqtSignal(str)  # message to be shown to user

    def __init__(self):
        super().__init__()

    @pyqtSlot()
    def work(self):
        self.sig_msg.emit('Hello from inside the thread!')

        result = 1 + 1
        result2 = 1 + 2


class MyWidget(QWidget):

    def __init__(self):
        super().__init__()

        self.setWindowTitle("Thread Example")

        form_layout = QVBoxLayout()

        self.setLayout(form_layout)
        self.resize(400, 200)

        self.button_start_threads = QPushButton("Start")
        self.button_start_threads.clicked.connect(self.start_threads)

        self.label = QLabel()

        form_layout.addWidget(self.label)
        form_layout.addWidget(self.button_start_threads)

        QThread.currentThread().setObjectName('main')

        self.__threads = None

    def start_threads(self):
        self.__threads = []

        worker = Worker()
        thread = QThread()
        thread.setObjectName('thread')
        self.__threads.append((thread, worker))  # need to store worker too otherwise will be gc'd
        worker.moveToThread(thread)

        worker.sig_msg.connect(self.label.setText)

        thread.started.connect(worker.work)
        thread.start() 


if __name__ == "__main__":
    app = QApplication([])

    form = MyWidget()
    form.show()

    sys.exit(app.exec_())

@brettcannon brettcannon reopened this May 15, 2018
@brettcannon brettcannon added needs verification and removed info-needed Issue requires more information from poster labels May 15, 2018
@ChrisK91
Copy link

I don't really understand much about debuggers, but seems like PyCharm had the same problem as per this discussion: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206600785-Breakpoints-in-a-QThread-are-not-caught

@d3r3kk
Copy link

d3r3kk commented May 22, 2018

Opened issue microsoft/ptvsd#428 to track the necessary work.

@DonJayamanne
Copy link
Author

@ChrisK91
This should work in the new Experimental debugger.
Please could you try this out.

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed needs upstream fix labels Aug 3, 2018
@DonJayamanne
Copy link
Author

@ChrisK91
This issue has been resolved.
You can validate this by installing the latest development version of the extension. Instructions for the installation of this dev version can be found here https://github.com/Microsoft/vscode-python/blob/master/CONTRIBUTING.md#development-build.

Please feel free to reopen the issue if it persists, else ping back on this issue and we'll open it up for you.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

4 participants