microsoft / microsoft/vscode-python-debugger

Bug:Debug didn't work in Qthread

Aperta
#697 6 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature-request needs community feedback
Lingua principale
TypeScript
Stelle
181
Fork
126
Merge medio
2g 3h
PR unite (30g)
3

Descrizione

Description:

When I use Qt for Pyside6, I open a Qthread sub thread in the main thread and add a breakpoint inside the sub thread, but Python debugger does not enter the sub thread,it just didn't work

Origin Code:
main.py:

import sys
from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton, QTextEdit, QVBoxLayout, QWidget
from PySide6.QtCore import Qt
from worker_thread import WorkerThread

class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QThread Debug Test")
        self.setGeometry(100, 100, 400, 300)
        
        # 创建中央部件和布局
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        layout = QVBoxLayout(central_widget)
        
        # 创建按钮
        self.start_button = QPushButton("Start Thread")
        self.start_button.clicked.connect(self.start_thread)
        layout.addWidget(self.start_button)
        
        # 创建文本显示区域
        self.text_edit = QTextEdit()
        self.text_edit.setReadOnly(True)
        layout.addWidget(self.text_edit)
        
        # 创建工作线程
        self.worker_thread = None
    
    def start_thread(self):
        if self.worker_thread is None or not self.worker_thread.isRunning():
            self.worker_thread = WorkerThread()
            self.worker_thread.message_signal.connect(self.update_text)
            self.worker_thread.start()
            self.text_edit.append("Thread started...")
    
    def update_text(self, message):
        self.text_edit.append(message)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    sys.exit(app.exec()) 

sub_thread.py:

from PySide6.QtCore import QThread, Signal
import time

class WorkerThread(QThread):
    message_signal = Signal(str)
    
    def __init__(self):
        super().__init__()
        self.running = True
    
    def run(self):
        count = 0
        while self.running and count < 10:
            count += 1
            self.message_signal.emit(f"Count: {count}")
            time.sleep(1)  # 模拟耗时操作
        
        self.message_signal.emit("Thread finished!")
    
    def stop(self):
        self.running = False 

Where is the sub-thread?

Image

Where is the breakpoint?

Image

What's the Performance?
Set the breakpoint and push the button,then you'll find that Python Debugger didn't work in the workthread(sub-thread)!

Image

Image

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo il problema segnalato con gli esempi forniti main.py e sub_thread.py, impostando un punto di interruzione in WorkerThread.run. Esamina quindi la gestione dei thread del debugger e gli eventuali test esistenti per il supporto di PySide6 o QThread. Il lavoro è completato quando il punto di interruzione nel thread di lavoro viene raggiunto durante una sessione di debug di VS Code.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.