Skip to content

Commit a1807ab

Browse files
committed
uvloop.close can't be weakref'd
hold a regular reference on the object, instead on the object to keep the reference count the same
1 parent 377dcd9 commit a1807ab

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

asyncio_atexit.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121

2222
class _RegistryEntry:
2323
def __init__(self, loop):
24-
self._close_ref = weakref.WeakMethod(loop.close)
24+
try:
25+
self._close_ref = weakref.WeakMethod(loop.close)
26+
except TypeError:
27+
# not everything can be weakref'd (Extensions such as uvloop).
28+
# Hold a regular reference _on the object_, in those cases
29+
loop._atexit_orig_close = loop.close
30+
self._close_ref = lambda: loop._atexit_orig_close
2531
self.callbacks = []
2632

2733
def close(self):

0 commit comments

Comments
 (0)