@@ -33,7 +33,7 @@ async def coro():
33
33
for _ in range (100 ):
34
34
tasks .add (tg .create_task (coro ()))
35
35
36
- all_tasks = self .all_tasks (loop )
36
+ all_tasks = asyncio .all_tasks (loop )
37
37
self .assertEqual (len (all_tasks ), 101 )
38
38
39
39
for task in all_tasks :
@@ -77,15 +77,15 @@ async def main():
77
77
for i in range (1000 ):
78
78
with lock :
79
79
asyncio .create_task (coro ())
80
- tasks = self .all_tasks (loop )
80
+ tasks = asyncio .all_tasks (loop )
81
81
done .wait ()
82
82
83
83
runner = threading .Thread (target = lambda : asyncio .run (main ()))
84
84
85
85
def check ():
86
86
started .wait ()
87
87
with lock :
88
- self .assertSetEqual (tasks & self .all_tasks (loop ), tasks )
88
+ self .assertSetEqual (tasks & asyncio .all_tasks (loop ), tasks )
89
89
90
90
threads = [threading .Thread (target = check ) for _ in range (10 )]
91
91
runner .start ()
@@ -167,15 +167,23 @@ async def main():
167
167
168
168
169
169
class TestPyFreeThreading (TestFreeThreading , TestCase ):
170
- all_tasks = staticmethod (asyncio .tasks ._py_all_tasks )
171
170
172
171
def setUp (self ):
173
172
self ._old_current_task = asyncio .current_task
174
173
asyncio .current_task = asyncio .tasks .current_task = asyncio .tasks ._py_current_task
174
+ self ._old_all_tasks = asyncio .all_tasks
175
+ asyncio .all_tasks = asyncio .tasks .all_tasks = asyncio .tasks ._py_all_tasks
176
+ self ._old_Task = asyncio .Task
177
+ asyncio .Task = asyncio .tasks .Task = asyncio .tasks ._PyTask
178
+ self ._old_Future = asyncio .Future
179
+ asyncio .Future = asyncio .futures .Future = asyncio .futures ._PyFuture
175
180
return super ().setUp ()
176
181
177
182
def tearDown (self ):
178
183
asyncio .current_task = asyncio .tasks .current_task = self ._old_current_task
184
+ asyncio .all_tasks = asyncio .tasks .all_tasks = self ._old_all_tasks
185
+ asyncio .Task = asyncio .tasks .Task = self ._old_Task
186
+ asyncio .Future = asyncio .tasks .Future = self ._old_Future
179
187
return super ().tearDown ()
180
188
181
189
def factory (self , loop , coro , ** kwargs ):
@@ -184,15 +192,23 @@ def factory(self, loop, coro, **kwargs):
184
192
185
193
@unittest .skipUnless (hasattr (asyncio .tasks , "_c_all_tasks" ), "requires _asyncio" )
186
194
class TestCFreeThreading (TestFreeThreading , TestCase ):
187
- all_tasks = staticmethod (getattr (asyncio .tasks , "_c_all_tasks" , None ))
188
195
189
196
def setUp (self ):
190
197
self ._old_current_task = asyncio .current_task
191
198
asyncio .current_task = asyncio .tasks .current_task = asyncio .tasks ._c_current_task
199
+ self ._old_all_tasks = asyncio .all_tasks
200
+ asyncio .all_tasks = asyncio .tasks .all_tasks = asyncio .tasks ._c_all_tasks
201
+ self ._old_Task = asyncio .Task
202
+ asyncio .Task = asyncio .tasks .Task = asyncio .tasks ._CTask
203
+ self ._old_Future = asyncio .Future
204
+ asyncio .Future = asyncio .futures .Future = asyncio .futures ._CFuture
192
205
return super ().setUp ()
193
206
194
207
def tearDown (self ):
195
208
asyncio .current_task = asyncio .tasks .current_task = self ._old_current_task
209
+ asyncio .all_tasks = asyncio .tasks .all_tasks = self ._old_all_tasks
210
+ asyncio .Task = asyncio .tasks .Task = self ._old_Task
211
+ asyncio .Future = asyncio .futures .Future = self ._old_Future
196
212
return super ().tearDown ()
197
213
198
214
0 commit comments