File tree Expand file tree Collapse file tree 3 files changed +36
-4
lines changed Expand file tree Collapse file tree 3 files changed +36
-4
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
- 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
25
31
self .callbacks = []
26
32
27
33
def close (self ):
Original file line number Diff line number Diff line change @@ -20,7 +20,9 @@ py_modules = asyncio_atexit
20
20
python_requires = >=3.6
21
21
22
22
[options.extras_require]
23
- test = pytest
23
+ test =
24
+ pytest
25
+ uvloop
24
26
25
27
[tool:pytest]
26
28
# asyncio_mode = auto
Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import sys
3
3
4
+ try :
5
+ import uvloop
6
+ except ImportError :
7
+ uvloop = None
8
+
9
+ import pytest
10
+
4
11
import asyncio_atexit
5
12
6
13
if sys .version_info >= (3 , 7 ):
@@ -15,7 +22,24 @@ def asyncio_run(coro):
15
22
loop .close ()
16
23
17
24
18
- def test_asyncio_atexit ():
25
+ policies = ["default" ]
26
+ if uvloop is not None :
27
+ policies .append ("uvloop" )
28
+
29
+
30
+ @pytest .fixture (params = policies )
31
+ def policy (request ):
32
+ before_policy = asyncio .get_event_loop_policy ()
33
+ if request .param == "default" :
34
+ policy = asyncio .DefaultEventLoopPolicy ()
35
+ elif request .param == "uvloop" :
36
+ policy = uvloop .EventLoopPolicy ()
37
+ asyncio .set_event_loop_policy (policy )
38
+ yield
39
+ asyncio .set_event_loop_policy (before_policy )
40
+
41
+
42
+ def test_asyncio_atexit (policy ):
19
43
sync_called = False
20
44
async_called = False
21
45
@@ -37,7 +61,7 @@ async def test():
37
61
assert async_called
38
62
39
63
40
- def test_unregister ():
64
+ def test_unregister (policy ):
41
65
sync_called = False
42
66
43
67
def sync_cb ():
You can’t perform that action at this time.
0 commit comments