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

QSignalSpy stops debugger without any error message #1668

Closed
bodote opened this issue Sep 10, 2024 · 2 comments
Closed

QSignalSpy stops debugger without any error message #1668

bodote opened this issue Sep 10, 2024 · 2 comments
Labels
needs repro Issue has not been reproduced yet

Comments

@bodote
Copy link

bodote commented Sep 10, 2024

Type: Bug

Behaviour

Debugging lines at and after QSignalSpy breaks the debugger, it quits without any error message.
signal_emitter = SignalEmitter() spy = QSignalSpy(signal_emitter.xPlaneAddrPortSignal)

Steps to reproduce:

import sys
from PySide6.QtWidgets import QApplication, QWidget
from PySide6.QtCore import QObject, Signal, SignalInstance
from PySide6.QtNetwork import QHostAddress
from PySide6.QtTest import QSignalSpy

class SignalEmitter(QObject):
    xPlaneAddrPortSignal = Signal(QHostAddress, int)

class CustomWidget(QWidget):
    def __init__(self):
        super().__init__()
        # Initialize your custom widget here

def main():
    # app = QApplication(sys.argv)
    app = QApplication(sys.argv)
    app.processEvents()
    widget = CustomWidget()
    widget.show() 
    signal_emitter = SignalEmitter()
    spy = QSignalSpy(signal_emitter.xPlaneAddrPortSignal)

    def signal_handler(host: QHostAddress, port: int):
        print(f"Signal emitted: Host - {host.toString()}, Port - {port}")

    signal_emitter.xPlaneAddrPortSignal.connect(signal_handler)    
    # To emit the signal (for testing purposes):
    signal_emitter.xPlaneAddrPortSignal.emit(QHostAddress("127.0.0.1"), 8080)
   
    if spy.count() >= 1:
        print("spy.count() >=1")
    print("the end")
    sys.exit(app.exec())
   

if __name__ == "__main__":
    main()

start debugger in VSCode 1.93.0 with Python Debugger v2024.10.0
set breakpoint at spy = QSignalSpy(signal_emitter.xPlaneAddrPortSignal) , then press "next" in debugger controls
set breakpoint at print("the end") and press "continue"

the debugger quits without any message before it reaches print("the end") . but when running the program without the debugger, it works just fine.

debugpy

Diagnostic data

```` 2024-09-10 08:44:32.248 [info] DAP Server launched with command: /Users/bodo.teichmann/dev/flightsim_raspi/pyG5/.venv/bin/python /Users/bodo.teichmann/.vscode/extensions/ms-python.debugpy-2024.10.0-darwin-arm64/bundled/libs/debugpy/adapter 2024-09-10 08:44:32.392 [info] Received 'debugpySockets' event from debugpy. 2024-09-10 08:44:32.393 [info] Received 'debugpySockets' event from debugpy. 2024-09-10 08:44:32.395 [info] Received 'debugpySockets' event from debugpy. 2024-09-10 08:44:32.942 [info] Received 'debugpySockets' event from debugpy. 2024-09-10 08:44:38.921 [info] Received 'debugpySockets' event from debugpy. 2024-09-10 08:44:38.922 [info] Received 'debugpySockets' event from debugpy. ``` launch.json configuration not used `launch.json`, just used "Python Debugger: Python File"

XXX

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

XXX

Output for Python Debugger in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python Debugger)

XXX

Extension version: 2024.10.0
VS Code version: Code 1.93.0 (Universal) (4849ca9bdf9666755eb463db297b69e5385090e3, 2024-09-04T13:02:38.431Z)
OS version: Darwin arm64 23.6.0
Modes:

  • Python version (& distribution if applicable, e.g. Anaconda): 3.12.3
  • Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): VirtualEnvironment
System Info
Item Value
CPUs Apple M1 (8 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 1, 4, 4
Memory (System) 16.00GB (0.05GB free)
Process Argv --crash-reporter-id 41815999-c6d4-4cd1-a9ae-96ab587a20ec
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
2i9eh265:30646982
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonnoceb:30805159
asynctok:30898717
pythonmypyd1:30879173
2e7ec940:31000449
pythontbext0:30879054
accentitlementst:30995554
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
dsvsc021:30996838
jg8ic977:31013176
a69g1124:31058053
dvdeprecation:31068756
dwnewjupyter:31046869
impr_priority:31102340
nativerepl1:31104043
refactort:31108082
pythonrstrctxt:31112756
flighttreat:31119336
wkspc-onlycs-t:31132770
wkspc-ranged-t:31125599
fje88620:31121564

@bodote
Copy link
Author

bodote commented Sep 10, 2024

found a not pleasant work around:
instead of using spy = QSignalSpy(signal_emitter.xPlaneAddrPortSignal) and spy.wait(), I used
loop = QEventLoop() and loop.exec() , that also works with the debugpy, although this solution is more cumbersome.

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python-debugger Sep 10, 2024
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Sep 10, 2024
@judej judej assigned debonte and unassigned judej and debonte Oct 14, 2024
@judej
Copy link

judej commented Oct 23, 2024

@bodote, this is likely due to way QSignalSpy pauses execution when you call spy.wiat() while it waits for the signal to be emitted. Debugpy likely does not deal with the blocking wait correctly and exits prematurely.

Since you've found that replacing QSignalSpy with QEventLoop fixes the debugger quitting issue, it suggests that QSignalSpy’s internal handling of signal emissions (even without explicitly using wait()) may interfere with the debugger's ability to manage the Qt event loop correctly.

Hope this helps, alas there isn't a less cumbersome workaround.

thanks

@judej judej closed this as completed Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs repro Issue has not been reproduced yet
Projects
None yet
Development

No branches or pull requests

3 participants