microsoft / microsoft/vscode-python-debugger

Bug:Debug didn't work in Qthread

Đang mở
#697 6 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

feature-request needs community feedback
Ngôn ngữ chính
TypeScript
Star
180
Fork
126
Merge trung bình
2 ngày 3 giờ
Pull request đã merge (30 ngày)
3

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách tái hiện báo cáo với các ví dụ main.py và sub_thread.py được cung cấp, đặt một điểm dừng trong WorkerThread.run. Sau đó, kiểm tra việc xử lý thread của trình gỡ lỗi và mọi bài kiểm thử hiện có cho việc hỗ trợ PySide6 hoặc QThread. Công việc được xem là hoàn tất khi điểm dừng trong worker thread được chạm tới trong một phiên gỡ lỗi VS Code.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.