Skip to content

Commit 53b3519

Browse files
occasionallydavidTheGreatCabbage
authored andcommitted
Catch selector remove_writer() calls in Python>=3.9
Fixes #28, fixes #27. In Python 3.9, selector_events.py stopped internally using the `add_writer()` and `remove_writer()` public class interface, instead calling `_add_writer()` and `_remove_writer()`. This was broken upstream in python/cpython@3a2667d91e3 This meant the `_remove_writer()` call was never unregistering the QSocketNotifier, as qasync does not override that method. Rather than crash, the write callback was simply ignoring the duplicate calls, resulting in 100% CPU. Cope with this by overriding the internal method names instead. This looks like it will work at least as far back as Python 3.6. The upstream Python repository has broken tags somehow so I can't check back further.
1 parent 060828b commit 53b3519

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

qasync/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def time(self):
460460
"""Get time according to event loop's clock."""
461461
return time.monotonic()
462462

463-
def add_reader(self, fd, callback, *args):
463+
def _add_reader(self, fd, callback, *args):
464464
"""Register a callback for when a file descriptor is ready for reading."""
465465
self._check_closed()
466466

@@ -484,7 +484,7 @@ def add_reader(self, fd, callback, *args):
484484
)
485485
self._read_notifiers[fd] = notifier
486486

487-
def remove_reader(self, fd):
487+
def _remove_reader(self, fd):
488488
"""Remove reader callback."""
489489
if self.is_closed():
490490
return
@@ -498,7 +498,7 @@ def remove_reader(self, fd):
498498
notifier.setEnabled(False)
499499
return True
500500

501-
def add_writer(self, fd, callback, *args):
501+
def _add_writer(self, fd, callback, *args):
502502
"""Register a callback for when a file descriptor is ready for writing."""
503503
self._check_closed()
504504
try:
@@ -521,7 +521,7 @@ def add_writer(self, fd, callback, *args):
521521
)
522522
self._write_notifiers[fd] = notifier
523523

524-
def remove_writer(self, fd):
524+
def _remove_writer(self, fd):
525525
"""Remove writer callback."""
526526
if self.is_closed():
527527
return

0 commit comments

Comments
 (0)