Skip to content

Commit cf441dc

Browse files
authored
Merge pull request #151 from danielrh/native_windows_lock
Use threading.Lock instead of QMutex to workaround QMutexLocker bug in PyQt6
2 parents d41ee94 + ed4fc1f commit cf441dc

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/qasync/_windows.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import asyncio
1212
import sys
13+
import threading
1314

1415
try:
1516
import _overlapped
@@ -63,7 +64,7 @@ class _IocpProactor(windows_events.IocpProactor):
6364
def __init__(self):
6465
self.__events = []
6566
super(_IocpProactor, self).__init__()
66-
self._lock = QtCore.QMutex()
67+
self._lock = threading.Lock()
6768

6869
def select(self, timeout=None):
6970
"""Override in order to handle events in a threadsafe manner."""
@@ -81,50 +82,50 @@ def close(self):
8182
# in the order they appear in the base class source code.
8283

8384
def recv(self, conn, nbytes, flags=0):
84-
with QtCore.QMutexLocker(self._lock):
85+
with self._lock:
8586
return super(_IocpProactor, self).recv(conn, nbytes, flags)
8687

8788
def recv_into(self, conn, buf, flags=0):
88-
with QtCore.QMutexLocker(self._lock):
89+
with self._lock:
8990
return super(_IocpProactor, self).recv_into(conn, buf, flags)
9091

9192
def recvfrom(self, conn, nbytes, flags=0):
92-
with QtCore.QMutexLocker(self._lock):
93+
with self._lock:
9394
return super(_IocpProactor, self).recvfrom(conn, nbytes, flags)
9495

9596
def recvfrom_into(self, conn, buf, flags=0):
96-
with QtCore.QMutexLocker(self._lock):
97+
with self._lock:
9798
return super(_IocpProactor, self).recvfrom_into(conn, buf, flags)
9899

99100
def sendto(self, conn, buf, flags=0, addr=None):
100-
with QtCore.QMutexLocker(self._lock):
101+
with self._lock:
101102
return super(_IocpProactor, self).sendto(conn, buf, flags, addr)
102103

103104
def send(self, conn, buf, flags=0):
104-
with QtCore.QMutexLocker(self._lock):
105+
with self._lock:
105106
return super(_IocpProactor, self).send(conn, buf, flags)
106107

107108
def accept(self, listener):
108-
with QtCore.QMutexLocker(self._lock):
109+
with self._lock:
109110
return super(_IocpProactor, self).accept(listener)
110111

111112
def connect(self, conn, address):
112-
with QtCore.QMutexLocker(self._lock):
113+
with self._lock:
113114
return super(_IocpProactor, self).connect(conn, address)
114115

115116
def sendfile(self, sock, file, offset, count):
116-
with QtCore.QMutexLocker(self._lock):
117+
with self._lock:
117118
return super(_IocpProactor, self).sendfile(sock, file, offset, count)
118119

119120
def accept_pipe(self, pipe):
120-
with QtCore.QMutexLocker(self._lock):
121+
with self._lock:
121122
return super(_IocpProactor, self).accept_pipe(pipe)
122123

123124
# connect_pipe() does not actually use the delayed completion machinery.
124125

125126
# This takes care of wait_for_handle() too.
126127
def _wait_for_handle(self, handle, timeout, _is_cancel):
127-
with QtCore.QMutexLocker(self._lock):
128+
with self._lock:
128129
return super(_IocpProactor, self)._wait_for_handle(
129130
handle, timeout, _is_cancel
130131
)
@@ -148,7 +149,7 @@ def _poll(self, timeout=None):
148149
break
149150
ms = 0
150151

151-
with QtCore.QMutexLocker(self._lock):
152+
with self._lock:
152153
err, transferred, key, address = status
153154
try:
154155
f, ov, obj, callback = self._cache.pop(address)

0 commit comments

Comments
 (0)