You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TypeError: arguments did not match any overloaded call QMutexLocker #128
Exception in callback _ProactorReadPipeTransport._loop_reading(<_OverlappedF...hed result=10>)
handle: <Handle _ProactorReadPipeTransport._loop_reading(<_OverlappedF...hed result=10>)>
Traceback (most recent call last):
File "asyncio\events.py", line 80, in _run
File "asyncio\proactor_events.py", line 301, in _loop_reading
File "qasync\_windows.py", line 86, in recv_into
TypeError: arguments did not match any overloaded call:
QMutexLocker(mutex: Optional[QMutex]): argument 1 has unexpected type 'QMutexLocker'
QMutexLocker(mutex: Optional[QRecursiveMutex]): argument 1 has unexpected type 'QMutexLocker'
Traceback (most recent call last):
File "qasync\_windows.py", line 196, in run
File "qasync\_windows.py", line 69, in select
File "qasync\_windows.py", line 149, in _poll
TypeError: arguments did not match any overloaded call:
QMutexLocker(mutex: Optional[QMutex]): argument 1 has unexpected type 'QMutexLocker'
QMutexLocker(mutex: Optional[QRecursiveMutex]): argument 1 has unexpected type 'QMutexLocker'
File "C:\Users\LabUser\AppData\Local\Programs\Python\Python311\Lib\asyncio\streams.py", line 332, in write
self._transport.write(data)
File "C:\Users\LabUser\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 365, in write
self._loop_writing(data=bytes(data))
File "C:\Users\LabUser\AppData\Local\Programs\Python\Python311\Lib\asyncio\proactor_events.py", line 401, in _loop_writing
self._write_fut = self._loop._proactor.send(self._sock, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\LabUser\AppData\Local\pypoetry\Cache\virtualenvs\artiq-oitg-UIB2HjkM-py3.11\Lib\site-packages\qasync\_windows.py", line 102, in send
with QtCore.QMutexLocker(self._lock):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: arguments did not match any overloaded call:
QMutexLocker(mutex: Optional[QMutex]): argument 1 has unexpected type 'QMutexLocker'
QMutexLocker(mutex: Optional[QRecursiveMutex]): argument 1 has unexpected type 'QMutexLocker'
I strongly suspect that this involves memory corruption or lifetime management issues, as self._lock is obviously not itself a QMutexLocker.
@blluv: Do you have a stand-alone reproducer for this?
May not be totally related, but I was getting errors like this when using the QApplication from Pyside instead of qasync. Switching to the qasync one fixed the async crashes I was getting.
This was after determining that these crashes were memory faults by looking at the windows event viewer. For future readers, if you get unexplainable crashes from PyQT / Pyside, add this to your code to get the traceback.
May not be totally related, but I was getting errors like this when using the QApplication from Pyside instead of qasync. Switching to the qasync one fixed the async crashes I was getting.
Huh – isn't that just a re-exported version of the underlying PyQt/PySide one, though?
I got the similar exception as above:
(It was just some simple asyncio task running at background that uses aiohttp and updates the UI.)
Traceback (most recent call last):
File "{proj_path}\.venv\Lib\site-packages\qasync\_windows.py", line 196, in run
events = self.__proactor.select(0.01)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "{proj_path}\.venv\Lib\site-packages\qasync\_windows.py", line 69, in select
self._poll(timeout)
File "{proj_path}\.venv\Lib\site-packages\qasync\_windows.py", line 149, in _poll
with QtCore.QMutexLocker(self._lock):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: arguments did not match any overloaded call:
QMutexLocker(mutex: QMutex): argument 1 has unexpected type 'QMutexLocker'
QMutexLocker(mutex: QRecursiveMutex): argument 1 has unexpected type 'QMutexLocker'
The exception appears to be a type mismatch caught at runtime ?
The exception happens out of nowhere, cannot determine if my code or qasync code or other triggers that.
The following "Application Error" found from windows event viewer seems related:
The error code 0xc0000409 indicates a stack buffer overflow, which can occur due to various reasons such as a corrupt file or memory issue.
0xc0000409 means STATUS_STACK_BUFFER_OVERRUN.
In other words, something in your program is writing past the current stack frame, corrupting data on the stack. The program has detected this and rather than let it continue, has thrown an exception.
looks like "memory fault in official Qt6Core.dll" leads to "Type mismatch exception in qasync _windows.py",
but self._lock is QtCore.QMutex() instance, how comes that memory fault (in c++'s view?) interpreted as a type mismatch exception (in python's view?) ?
This is not a qasync bug. I was able to reproduce it on linux by pattern matching what Qasync was doing
importthreadingimporttimefromPyQt6.QtCoreimportQMutex, QMutexLocker, QCoreApplicationimportsysclassSharedResource:
def__init__(self):
self._lock=QMutex()
print(f"Initial: self._lock is {type(self._lock).__name__} at {id(self._lock)}")
defmethod_a(self):
"""Called from thread A"""foriinrange(10000):
try:
# This is the pattern used in qasyncwithQMutexLocker(self._lock):
passexceptTypeErrorase:
print(f"Thread A failed at iteration {i}: {e}")
print(f"self._lock is now {type(self._lock).__name__} at {id(self._lock)}")
returnFalsereturnTruedefmethod_b(self):
"""Called from thread B (main thread)"""foriinrange(10000):
try:
withQMutexLocker(self._lock):
passexceptTypeErrorase:
print(f"Thread B failed at iteration {i}: {e}")
print(f"self._lock is now {type(self._lock).__name__} at {id(self._lock)}")
returnFalsereturnTruedefmain():
app=QCoreApplication(sys.argv)
resource=SharedResource()
# Start thread Athread_a=threading.Thread(target=resource.method_a)
thread_a.start()
# Run method_b in main threadsuccess_b=resource.method_b()
# Wait for thread Athread_a.join()
print(f"\nFinal: self._lock is {type(resource._lock).__name__} at {id(resource._lock)}")
ifnotsuccess_b:
print("\nBUG REPRODUCED: QMutex was replaced with QMutexLocker!")
return1return0if__name__=="__main__":
sys.exit(main())
gives
python min.py
Initial: self._lock is QMutex at 139328410447568
Exception in thread Thread-1 (method_a):
Traceback (most recent call last):
File "/usr/lib/python3.12/threading.py", line 1073, in bootstrapinner
self.run()
File "/usr/lib/python3.12/threading.py", line 1010, in run
self._target(*self._args, **self._kwargs)
File "/home/danielrh/dev/pyqtbug/min.py", line 22, in method_a
with QMutexLocker(self._lock):
^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: wrapped C/C++ object of type QMutex has been deleted
Segmentation fault (core dumped)
This was PyQt6 version: 6.6.1 or 6.9.1
Python version: 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0]
the same script has more trouble on Python 3.11.9 with PyQt6 version 6.9.1 for some reason
Thread 3 "python" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff31fe6c0 (LWP 340823)]
Downloading source file /usr/src/python3.12-3.12.3-1ubuntu0.7/build-static/../Objects/weakrefobject.c
clear_weakref (self=0x7ffff7398e30) at ../Objects/weakrefobject.c:60
warning: 60 ../Objects/weakrefobject.c: No such file or directory
--Type <RET> for more, q to quit, c to continue without paging--
#0 clear_weakref (self=0x7ffff7398e30) at ../Objects/weakrefobject.c:60
#1 0x00000000005c8ce4 in PyObject_ClearWeakRefs (object=<optimized out>)
at ../Objects/weakrefobject.c:952
#2 0x000000000059ea58 in subtype_dealloc (self=0x7ffff7398cd0)
at ../Objects/typeobject.c:1974
#3 0x00000000005e0105 in _PyEval_EvalFrameDefault (tstate=<optimized out>,
frame=<optimized out>, throwflag=<optimized out>)
at Python/bytecodes.c:2731
#4 0x000000000054cb32 in _PyObject_VectorcallTstate (kwnames=0x0, nargsf=1,
args=0x7ffff31fde18, callable=0x7ffff749d580, tstate=0xd8f0b0)
at ../Include/internal/pycore_call.h:92
#5 method_vectorcall (method=<optimized out>,
args=0xb49140 <_PyRuntime+76288>, nargsf=<optimized out>, kwnames=0x0)
at ../Objects/classobject.c:69
#6 0x00000000006f80dc in thread_run (boot_raw=0xd8f080)
at ../Modules/_threadmodule.c:1114
#7 0x00000000006b931c in pythread_wrapper (arg=<optimized out>)
at ../Python/thread_pthread.h:237
#8 0x00007ffff7c9caa4 in start_thread (arg=<optimized out>)
at ./nptl/pthread_create.c:447
#9 0x00007ffff7d29c3c in clone3 ()
You can import this file at the beginning of your main and it should fix the problem by patching in native python threading.Lock() instead of using PyQt6's broken lock.
@danielrh Thanks, this is great! I did need to significantly increase the loop iteration count in your reproduction case (Python 3.12/Windows 11), but that's pretty cut and dry. When starting to look into this previously, avoiding QMutexLocker did seem to fix it, but I was never quite sure since I didn't have a self-contained test case yet. Sadly, I don't have commit access here, but I'll immediately roll out danielrh@b497a15 in the application used across my research group.
Activity
HubKing commentedon Jan 26, 2025
Is this project dead?
st-walker commentedon Jan 26, 2025
I think the maintainers typically reply to say it's not dead but nothing ever gets merged so 🤷
See:
#119 (comment)
dnadlinger commentedon Jan 26, 2025
We are also seeing this on the latest release (in the context of https://github.com/m-labs/artiq on Windows):
I strongly suspect that this involves memory corruption or lifetime management issues, as
self._lockis obviously not itself aQMutexLocker.@blluv: Do you have a stand-alone reproducer for this?
dnadlinger commentedon Jan 26, 2025
It would be interesting to see whether this also occurs with PySide instead of PyQt.
halkony commentedon Jan 27, 2025
May not be totally related, but I was getting errors like this when using the
QApplicationfrom Pyside instead of qasync. Switching to the qasync one fixed the async crashes I was getting.halkony commentedon Jan 27, 2025
This was after determining that these crashes were memory faults by looking at the windows event viewer. For future readers, if you get unexplainable crashes from PyQT / Pyside, add this to your code to get the traceback.
dnadlinger commentedon Jan 27, 2025
Huh – isn't that just a re-exported version of the underlying PyQt/PySide one, though?
halkony commentedon Jan 27, 2025
It seems you are correct. Nevertheless my application hasn't had a random crash from a thread since I made that change. Seems preposterous.
dnadlinger commentedon Jan 27, 2025
And it wasn't maybe the auto-selelction causing you to switch to a different (Py)Qt library?
RichardReallyHard commentedon Mar 1, 2025
I got the similar exception as above:
(It was just some simple asyncio task running at background that uses aiohttp and updates the UI.)
The exception appears to be a type mismatch caught at runtime ?
The exception happens out of nowhere, cannot determine if my code or qasync code or other triggers that.
The following "Application Error" found from windows event viewer seems related:
from ms community or a stackoverflow question, the exception code seems to be a memory fault
looks like "memory fault in official Qt6Core.dll" leads to "Type mismatch exception in qasync _windows.py",
but self._lock is QtCore.QMutex() instance, how comes that memory fault (in c++'s view?) interpreted as a type mismatch exception (in python's view?) ?
Use threading.Lock instead of QMutex to make the system more efficien…
danielrh commentedon Aug 16, 2025
This is not a qasync bug. I was able to reproduce it on linux by pattern matching what Qasync was doing
gives
This was PyQt6 version: 6.6.1 or 6.9.1
Python version: 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0]
the same script has more trouble on Python 3.11.9 with PyQt6 version 6.9.1 for some reason
danielrh commentedon Aug 16, 2025
The stack trace is
danielrh commentedon Aug 16, 2025
Possibly this sequence of events:
danielrh commentedon Aug 16, 2025
I have a much smaller repro case:
danielrh commentedon Aug 16, 2025
You can import this file at the beginning of your main and it should fix the problem by patching in native python threading.Lock() instead of using PyQt6's broken lock.
pyqt6_mutex_patch.py
danielrh commentedon Aug 16, 2025
Perhaps developers of qasync can consider patching this in until Riverbank Computing fixes PyQt6
or avoiding the QMutexLocker by merging danielrh@b497a15
dnadlinger commentedon Aug 16, 2025
@danielrh Thanks, this is great! I did need to significantly increase the loop iteration count in your reproduction case (Python 3.12/Windows 11), but that's pretty cut and dry. When starting to look into this previously, avoiding
QMutexLockerdid seem to fix it, but I was never quite sure since I didn't have a self-contained test case yet. Sadly, I don't have commit access here, but I'll immediately roll out danielrh@b497a15 in the application used across my research group.Use threading.Lock instead of QMutex to make the system more efficien…
Use threading.Lock instead of QMutex to make the system more efficien…
hosaka commentedon Aug 28, 2025
Fixed in #151
using mainline qasync now CabbageDevelopment/qasync#128 is resolved