File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 11import asyncio
2+ import threading
23import unittest
34from threading import Thread
45from unittest import TestCase
@@ -58,6 +59,38 @@ def runner():
5859 with threading_helper .start_threads (threads ):
5960 pass
6061
62+ def test_all_tasks_different_thread (self ) -> None :
63+ loop = None
64+ started = threading .Event ()
65+
66+ async def coro ():
67+ await asyncio .sleep (0.01 )
68+
69+ lock = threading .Lock ()
70+ count = 0
71+
72+ async def main ():
73+ nonlocal count , loop
74+ loop = asyncio .get_running_loop ()
75+ started .set ()
76+ for i in range (1000 ):
77+ with lock :
78+ asyncio .create_task (coro ())
79+ count = len (self .all_tasks (loop ))
80+
81+ runner = threading .Thread (target = lambda : asyncio .run (main ()))
82+
83+ def check ():
84+ started .wait ()
85+ with lock :
86+ self .assertEqual (count , len (self .all_tasks (loop )))
87+
88+ threads = [threading .Thread (target = check ) for _ in range (10 )]
89+ threads .append (runner )
90+
91+ with threading_helper .start_threads (threads ):
92+ pass
93+
6194 def test_run_coroutine_threadsafe (self ) -> None :
6295 results = []
6396
You can’t perform that action at this time.
0 commit comments