Pycharm debugger not stopping on QThread breakpoints
The PyCharm debugger is not stopping on QThread breakpoints, even though pydevd seems to have qt-support enabled. Is this a known issue?
The breakpoints at "run" and "needsUpdateCurse" are not being triggered even though the code is being executed. Source code is visible here: https://github.com/cpw/lcurse
/usr/bin/python3.5 /home/cpw/pycharm-community-2016.2/helpers/pydev/pydevd.py --cmd-line --multiproc --qt-support --client 127.0.0.1 --port 43975 --file /home/cpw/projects/wow/lcurse/lcurse
PYDEVD_FILTER_LIBRARIES False
Started in multiproc mode
('Connecting to ', '127.0.0.1', ':', '43975')
('Connected.',)
debugger: received >>99 -1 38537
<<
Received command: ??? 99 -1 38537
Received port 38537
pydev debugger: process 17944 is connecting
('Connecting to ', '127.0.0.1', ':', '38537')
('Connected.',)
debugger: received >>501 1 0.1 UNIX
<<
Received command: CMD_VERSION 501 1 0.1 UNIX
Connected to pydev debugger (build 162.1967.10)
sending cmd --> CMD_VERSION 501 1 @@BUILD_NUMBER@@
debugger: received >>111 3 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 149 needsUpdateCurse THREAD None None
<<
Received command: CMD_SET_BREAK 111 3 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 149 needsUpdateCurse THREAD None None
Added breakpoint:/home/cpw/projects/wow/lcurse/modules/waitdlg.py - line:149 - func_name:b'needsUpdateCurse'
debugger: received >>111 5 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 177 run THREAD None None
111 7 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 129 __init__ THREAD None None
111 9 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 46 __init__ THREAD None None
111 11 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 87 startWorkerThreads THREAD None None
122 13 python-BaseException 0 1 0
146 15 SHOW_RETURN_VALUES 1
101 17
<<
Received command: CMD_SET_BREAK 111 5 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 177 run THREAD None None
Added breakpoint:/home/cpw/projects/wow/lcurse/modules/waitdlg.py - line:177 - func_name:b'run'
Received command: CMD_SET_BREAK 111 7 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 129 __init__ THREAD None None
Added breakpoint:/home/cpw/projects/wow/lcurse/modules/waitdlg.py - line:129 - func_name:b'__init__'
Received command: CMD_SET_BREAK 111 9 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 46 __init__ THREAD None None
Added breakpoint:/home/cpw/projects/wow/lcurse/modules/waitdlg.py - line:46 - func_name:b'__init__'
Received command: CMD_SET_BREAK 111 11 python-line /home/cpw/projects/wow/lcurse/modules/waitdlg.py 87 startWorkerThreads THREAD None None
Added breakpoint:/home/cpw/projects/wow/lcurse/modules/waitdlg.py - line:87 - func_name:b'startWorkerThreads'
Received command: CMD_ADD_EXCEPTION_BREAK 122 13 python-BaseException 0 1 0
Exceptions to hook on terminate: {'BaseException': <_pydevd_bundle.pydevd_breakpoints.ExceptionBreakpoint object at 0x7f94ecb1c438>}
Received command: CMD_SHOW_RETURN_VALUES 146 15 SHOW_RETURN_VALUES 1
Show return values: True
Received command: CMD_RUN 101 17
IDE_PROJECT_ROOTS ['/home/cpw/projects/wow/lcurse']
WARNING: gui translation file could not be found: /home/cpw/projects/wow/lcurse/translations/en_CA.qm
sending cmd --> CMD_THREAD_CREATE 103 2 <xml><thread name="MainThread" id="pid_17944_id_140277645368624" /></xml>
sending cmd --> CMD_THREAD_SUSPEND 105 4 <xml><thread id="pid_17944_id_140277645368624" stop_reason="111" message=""><frame id="140277603040232" name="__init__" file="/home/cpw/projects/wow/lcurse/modules/waitdlg.py" line="46"></frame><frame id="140277457097576" name="checkAddonForUpdate" file="/home/cpw/projects/wow/lcurse/modules/application.py" line="440"></frame><frame id="30349000" name="<module>" file="/home/cpw/projects/wow/lcurse/lcurse" line="49"></frame><frame id="30341496" name="execfile" file="/home/cpw/pycharm-community-2016.2/helpers/pydev/_pydev_imps/_pydev_execfile.py" line="18"></frame><frame id="30362056" name="run" file="/home/cpw/pycharm-community-2016.2/helpers/pydev/pydevd.py" line="964"></frame><frame id="24627160" name="<module>" file="/home/cpw/pycharm-community-2016.2/helpers/pydev/pydevd.py" line="1580"></frame></thread></xml>
debugger: received >>114 19 pid_17944_id_140277645368624 140277603040232 FRAME
<<
Received command: CMD_GET_FRAME 114 19 pid_17944_id_140277645368624 140277603040232 FRAME
debugger: received >>114 21 pid_17944_id_140277645368624 140277603040232 FRAME
<<
Received command: CMD_GET_FRAME 114 21 pid_17944_id_140277645368624 140277603040232 FRAME
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x7f94ecb1c898>')
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x7f94edd5bb00>')
sending cmd --> CMD_GET_FRAME 114 19 <xml><var name="__class__" type="pyqtWrapperType" qualifier="PyQt5.QtCore" value="pyqtWrapperType: <class 'waitdlg.CheckDlg'>" isContainer="True" /> <var name="addons" type="list" qualifier="builtins" value="<class 'list'>: [(0, 'AdiBags', 'http://mods.curse.com/addons/wow/adibags', 'v1.9.2', False)]" isContainer="True" /> <var name="parent" type="MainWidget" qualifier="modules.application" value="MainWidget: <modules.application.MainWidget object at 0x7f94ea13be58>" isContainer="True" /> <var name="self" type="CheckDlg" qualifier="waitdlg" value="CheckDlg: <waitdlg.CheckDlg object at 0x7f94bd4dc948>" isContainer="True" /> </xml>
sending cmd --> CMD_GET_FRAME 114 21 <xml><var name="__class__" type="pyqtWrapperType" qualifier="PyQt5.QtCore" value="pyqtWrapperType: <class 'waitdlg.CheckDlg'>" isContainer="True" /> <var name="addons" type="list" qualifier="builtins" value="<class 'list'>: [(0, 'AdiBags', 'http://mods.curse.com/addons/wow/adibags', 'v1.9.2', False)]" isContainer="True" /> <var name="parent" type="MainWidget" qualifier="modules.application" value="MainWidget: <modules.application.MainWidget object at 0x7f94ea13be58>" isContainer="True" /> <var name="self" type="CheckDlg" qualifier="waitdlg" value="CheckDlg: <waitdlg.CheckDlg object at 0x7f94bd4dc948>" isContainer="True" /> </xml>
debugger: received >>106 23 pid_17944_id_140277645368624
<<
Received command: CMD_THREAD_RUN 106 23 pid_17944_id_140277645368624
sending cmd --> CMD_THREAD_RUN 106 6 pid_17944_id_140277645368624 -1
sending cmd --> CMD_THREAD_CREATE 103 8 <xml><thread name="Dummy-6" id="pid_17944_id_140276795924040" /></xml>
sending cmd --> CMD_THREAD_SUSPEND 105 10 <xml><thread id="pid_17944_id_140276795924040" stop_reason="111" message=""><frame id="140276920522288" name="startWorkerThreads" file="/home/cpw/projects/wow/lcurse/modules/waitdlg.py" line="87"></frame><frame id="140276795158600" name="__call__" file="/home/cpw/pycharm-community-2016.2/helpers/pydev/_pydev_bundle/pydev_monkey.py" line="565"></frame></thread></xml>
debugger: received >>114 25 pid_17944_id_140276795924040 140276920522288 FRAME
<<
Received command: CMD_GET_FRAME 114 25 pid_17944_id_140276795924040 140276920522288 FRAME
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x7f94ecb1c470>')
sending cmd --> CMD_GET_FRAME 114 25 <xml><var name="self" type="CheckDlg" qualifier="waitdlg" value="CheckDlg: <waitdlg.CheckDlg object at 0x7f94bd4dc948>" isContainer="True" /> </xml>
debugger: received >>114 27 pid_17944_id_140276795924040 140276920522288 FRAME
<<
Received command: CMD_GET_FRAME 114 27 pid_17944_id_140276795924040 140276920522288 FRAME
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x7f94ba2ca470>')
sending cmd --> CMD_GET_FRAME 114 27 <xml><var name="self" type="CheckDlg" qualifier="waitdlg" value="CheckDlg: <waitdlg.CheckDlg object at 0x7f94bd4dc948>" isContainer="True" /> </xml>
debugger: received >>106 29 pid_17944_id_140277645368624
<<
Received command: CMD_THREAD_RUN 106 29 pid_17944_id_140277645368624
debugger: received >>106 31 pid_17944_id_140276795924040
<<
Received command: CMD_THREAD_RUN 106 31 pid_17944_id_140276795924040
sending cmd --> CMD_THREAD_RUN 106 12 pid_17944_id_140276795924040 -1
sending cmd --> CMD_THREAD_SUSPEND 105 14 <xml><thread id="pid_17944_id_140276795924040" stop_reason="111" message=""><frame id="140276795165888" name="__init__" file="/home/cpw/projects/wow/lcurse/modules/waitdlg.py" line="129"></frame><frame id="140276920522288" name="startWorkerThreads" file="/home/cpw/projects/wow/lcurse/modules/waitdlg.py" line="91"></frame><frame id="140276795158600" name="__call__" file="/home/cpw/pycharm-community-2016.2/helpers/pydev/_pydev_bundle/pydev_monkey.py" line="565"></frame></thread></xml>
debugger: received >>114 33 pid_17944_id_140276795924040 140276795165888 FRAME
<<
Received command: CMD_GET_FRAME 114 33 pid_17944_id_140276795924040 140276795165888 FRAME
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x7f94bc975f28>')
sending cmd --> CMD_GET_FRAME 114 33 <xml><var name="__class__" type="pyqtWrapperType" qualifier="PyQt5.QtCore" value="pyqtWrapperType: <class 'waitdlg.CheckWorker'>" isContainer="True" /> <var name="addon" type="tuple" qualifier="builtins" value="<class 'tuple'>: (0, 'AdiBags', 'http://mods.curse.com/addons/wow/adibags', 'v1.9.2', False)" isContainer="True" /> <var name="self" type="CheckWorker" qualifier="waitdlg" value="CheckWorker: <waitdlg.CheckWorker object at 0x7f94eda668b8>" isContainer="True" /> </xml>
debugger: received >>114 35 pid_17944_id_140276795924040 140276795165888 FRAME
<<
Received command: CMD_GET_FRAME 114 35 pid_17944_id_140276795924040 140276795165888 FRAME
('processing internal command ', '<_pydevd_bundle.pydevd_comm.InternalGetFrame object at 0x7f94ba2ca5c0>')
sending cmd --> CMD_GET_FRAME 114 35 <xml><var name="__class__" type="pyqtWrapperType" qualifier="PyQt5.QtCore" value="pyqtWrapperType: <class 'waitdlg.CheckWorker'>" isContainer="True" /> <var name="addon" type="tuple" qualifier="builtins" value="<class 'tuple'>: (0, 'AdiBags', 'http://mods.curse.com/addons/wow/adibags', 'v1.9.2', False)" isContainer="True" /> <var name="self" type="CheckWorker" qualifier="waitdlg" value="CheckWorker: <waitdlg.CheckWorker object at 0x7f94eda668b8>" isContainer="True" /> </xml>
debugger: received >>106 37 pid_17944_id_140277645368624
<<
Received command: CMD_THREAD_RUN 106 37 pid_17944_id_140277645368624
debugger: received >>106 39 pid_17944_id_140276795924040
<<
Received command: CMD_THREAD_RUN 106 39 pid_17944_id_140276795924040
sending cmd --> CMD_THREAD_RUN 106 16 pid_17944_id_140276795924040 -1
Process finished with exit code 137 (interrupted by signal 9: SIGKILL)
Please sign in to leave a comment.
Hi Carlos Ruiz Dominguez!
I've created an issue in our tracker: https://youtrack.jetbrains.com/issue/PY-21260
You've done a great research, and found the reason of the problem correctly. Thank you!
We'll implement a proper fix for it.
Interesting, I've had the same issue for many months, but I just assumed Pycharm Debugger didn't work well with PyQt.
However, a Qt4-Qt5 issue on matplotlib made me dig deeper, and what was my surprise when I realized that Pycharm was the culprit!! Basically, matplotlib chooses between PyQt4 or PyQt5 based on which one has already been imported to sys.modules [if none of them have been imported yet, then it chooses based on a user setting]. And matplotlib was breaking because my setting was to use PyQt5 but PyQt4 was in my sys.modules even though *I had never imported it*! When I ran the same script from the Terminal, it worked perfectly and matplotlib didn't break, and it was using PyQt5 as I had requested.
So here's what I found: in order to debug QThreads, PyCharm patches PyQt imports to insert hooks that will allow the debugger to trace QThreads. This is done in the file `/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_bundle/pydev_monkey_qt.py` (I assume windows will have a similar file structure rooted on the `Contents` folder).
Here's what's interesting: PyCharm determines which PyQt version to insert the hooks on by trying to load, *in this order*, PySide, PyQt4 and PyQt5 (instead of patching them all which is what seems logical to me). That means that if you have more than one of those modules installed (I have both PyQt4 and PyQt5), it'll only allow you to debug the one that comes earlier in that order (PyQt4 in my case). So I simply changed the order of imports to try PyQt5 *before* trying to import PyQt4, and... SUPRISE!!! Now the debugger stops in my QThreads!! Woooo :)
In case anyone is interested, here's my patched version of `pydev_monkey_qt.py` (line 12 defines whether qt5 should be preferred over qt4 or not, through the boolean variable `_prioritize_qt5`):
Thanks for the hint, @Carlos. In my case, I tried to install pyside (on OSX) but it was so broken I gave up and went with PyQt5. I had both installed via brew. I didn't have pyside imports in my program. After I removed pyside with brew, the breakpoints in QThreads started to work. This is definitely a bug in PyCharm.
Hi dear all,
Please add one more affected run. Seems to be same issue:
```
/home/sh/REPOS/python3_5_3/bin/python /opt/pycharm-2016.3.2/helpers/pydev/pydevd.py --multiproc --qt-support --client 127.0.0.1 --port 44604 --file /home/sh/REPOS/python3_5_3/bin/autoxtrabackup --backup -v -l DEBUG --defaults_file=/home/sh/txt.ff
PYDEVD_FILTER_LIBRARIES False
Started in multiproc mode
('Connecting to ', '127.0.0.1', ':', '44604')
('Connected.',)
debugger: received >>99 -1 41977
<<
Received command: ??? 99 -1 41977
Received port 41977
pydev debugger: process 16580 is connecting
Connected to pydev debugger (build 163.10154.50)
('Connecting to ', '127.0.0.1', ':', '41977')
('Connected.',)
debugger: received >>501 1 0.1 UNIX
<<
Received command: CMD_VERSION 501 1 0.1 UNIX
sending cmd --> CMD_VERSION 501 1 @@BUILD_NUMBER@@
debugger: received >>111 3 python-line /home/sh/REPOS/MySQL-AutoXtraBackup/autoxtrabackup.py 53 all_procedure ALL None None
<<
Received command: CMD_SET_BREAK 111 3 python-line /home/sh/REPOS/MySQL-AutoXtraBackup/autoxtrabackup.py 53 all_procedure ALL None None
Added breakpoint:/home/sh/REPOS/MySQL-AutoXtraBackup/autoxtrabackup.py - line:53 - func_name:b'all_procedure'
debugger: received >>146 5 SHOW_RETURN_VALUES 0
101 7
<<
Received command: CMD_SHOW_RETURN_VALUES 146 5 SHOW_RETURN_VALUES 0
Show return values: False
Received command: CMD_RUN 101 7
IDE_PROJECT_ROOTS ['/home/sh/REPOS/MySQL-AutoXtraBackup']
Patching args: ['/bin/sh', '-c', 'uname -p 2> /dev/null']
Process is not python, returning.
sending cmd --> CMD_PROCESS_CREATED 149 2 <process/>
Traceback (most recent call last):
File "/opt/pycharm-2016.3.2/helpers/pydev/pydevd.py", line 1596, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "/opt/pycharm-2016.3.2/helpers/pydev/pydevd.py", line 974, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/opt/pycharm-2016.3.2/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/sh/REPOS/python3_5_3/bin/autoxtrabackup", line 11, in <module>
load_entry_point('mysql-autoxtrabackup==1.4.4', 'console_scripts', 'autoxtrabackup')()
File "/home/sh/REPOS/python3_5_3/lib/python3.5/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/home/sh/REPOS/python3_5_3/lib/python3.5/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/home/sh/REPOS/python3_5_3/lib/python3.5/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/sh/REPOS/python3_5_3/lib/python3.5/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/home/sh/REPOS/python3_5_3/lib/python3.5/site-packages/mysql_autoxtrabackup-1.4.4-py3.5.egg/autoxtrabackup.py", line 69, in all_procedure
with pid_file: # User PidFile for locking to single instance
UnboundLocalError: local variable 'pid_file' referenced before assignment
'MySQL'
Process finished with exit code 1
```
Hi everyone! Since PyCharm 2017.1.1 you can define PyQt backend for debug session by setting environment variable PYDEVD_PYQT_MODE to 'pyqt4', 'pyqt5' or 'pyside'. It helps to solve the problem described in the original post.
I finally have this issue resolved, but it appears to be due to all the breakpoints I had set in other programs? After following the above recommendations with environment variables, I still couldn't get the debugger to stop on any breakpoints (running version 2017.1.4). However, upon clicking the view all breakpoints button (the icon with two red circles in the debug section...see image), the debugger now works. I obviuosly don't know enough about the debugger to understand why this fixed things, but after several hours of frustration, I'm just glad it works...hopefully this will help someone else out too.