File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change 21
21
22
22
class _RegistryEntry :
23
23
def __init__ (self , loop ):
24
+ if not hasattr (loop , "_atexit_orig_close" ):
25
+ # avoid double-patching
26
+ # weakrefs can get unresolved and then close called in __del__,
27
+ # so this seems unavoidable
28
+ loop ._atexit_orig_close = loop .close
24
29
try :
25
- self ._close_ref = weakref .WeakMethod (loop .close )
30
+ self ._close_ref = weakref .WeakMethod (loop ._atexit_orig_close )
26
31
except TypeError :
27
32
# not everything can be weakref'd (Extensions such as uvloop).
28
33
# Hold a regular reference _on the object_, in those cases
29
- loop ._atexit_orig_close = loop .close
30
34
self ._close_ref = lambda : loop ._atexit_orig_close
31
35
self .callbacks = []
32
36
Original file line number Diff line number Diff line change @@ -75,3 +75,20 @@ async def test():
75
75
76
76
asyncio_run (test ())
77
77
assert not sync_called
78
+
79
+
80
+ def test_run_raises (policy ):
81
+ sync_called = False
82
+
83
+ def sync_cb ():
84
+ nonlocal sync_called
85
+ sync_called = True
86
+
87
+ async def test ():
88
+ asyncio_atexit .register (sync_cb )
89
+ 1 / 0
90
+
91
+ with pytest .raises (ZeroDivisionError ):
92
+ asyncio_run (test ())
93
+
94
+ assert sync_called
You can’t perform that action at this time.
0 commit comments