From ed4fc1f967c1f7d21dda4c197983e861779f9ff4 Mon Sep 17 00:00:00 2001 From: Daniel Reiter Horn Date: Fri, 15 Aug 2025 11:50:32 -0700 Subject: [PATCH] Use threading.Lock instead of QMutex to make the system more efficient and try to attempt isolation of https://github.com/CabbageDevelopment/qasync/issues/128 --- src/qasync/_windows.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/qasync/_windows.py b/src/qasync/_windows.py index 8d4e232..3ff545d 100644 --- a/src/qasync/_windows.py +++ b/src/qasync/_windows.py @@ -10,6 +10,7 @@ import asyncio import sys +import threading try: import _overlapped @@ -63,7 +64,7 @@ class _IocpProactor(windows_events.IocpProactor): def __init__(self): self.__events = [] super(_IocpProactor, self).__init__() - self._lock = QtCore.QMutex() + self._lock = threading.Lock() def select(self, timeout=None): """Override in order to handle events in a threadsafe manner.""" @@ -81,50 +82,50 @@ def close(self): # in the order they appear in the base class source code. def recv(self, conn, nbytes, flags=0): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).recv(conn, nbytes, flags) def recv_into(self, conn, buf, flags=0): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).recv_into(conn, buf, flags) def recvfrom(self, conn, nbytes, flags=0): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).recvfrom(conn, nbytes, flags) def recvfrom_into(self, conn, buf, flags=0): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).recvfrom_into(conn, buf, flags) def sendto(self, conn, buf, flags=0, addr=None): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).sendto(conn, buf, flags, addr) def send(self, conn, buf, flags=0): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).send(conn, buf, flags) def accept(self, listener): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).accept(listener) def connect(self, conn, address): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).connect(conn, address) def sendfile(self, sock, file, offset, count): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).sendfile(sock, file, offset, count) def accept_pipe(self, pipe): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self).accept_pipe(pipe) # connect_pipe() does not actually use the delayed completion machinery. # This takes care of wait_for_handle() too. def _wait_for_handle(self, handle, timeout, _is_cancel): - with QtCore.QMutexLocker(self._lock): + with self._lock: return super(_IocpProactor, self)._wait_for_handle( handle, timeout, _is_cancel ) @@ -148,7 +149,7 @@ def _poll(self, timeout=None): break ms = 0 - with QtCore.QMutexLocker(self._lock): + with self._lock: err, transferred, key, address = status try: f, ov, obj, callback = self._cache.pop(address)