Lines Matching defs:asyncio
18 import asyncio
19 from asyncio import coroutines
20 from asyncio import futures
21 from asyncio import tasks
28 asyncio.set_event_loop_policy(None)
119 with self.assertRaises(asyncio.CancelledError) as cm:
132 with self.assertRaises(asyncio.CancelledError) as cm:
146 asyncio.gather(*[
151 other_loop = asyncio.new_event_loop()
169 task = asyncio.ensure_future(test(), loop=self.loop)
185 loop = asyncio.new_event_loop()
195 t = asyncio.ensure_future(notmuch(), loop=self.loop)
204 asyncio.ensure_future(a)
207 return asyncio.ensure_future(notmuch())
215 asyncio.set_event_loop(self.loop)
216 self.addCleanup(asyncio.set_event_loop, None)
217 t = asyncio.ensure_future(notmuch())
227 f = asyncio.ensure_future(f_orig)
233 loop = asyncio.new_event_loop()
237 f = asyncio.ensure_future(f_orig, loop=loop)
241 f = asyncio.ensure_future(f_orig, loop=self.loop)
248 t = asyncio.ensure_future(t_orig)
254 loop = asyncio.new_event_loop()
258 t = asyncio.ensure_future(t_orig, loop=loop)
262 t = asyncio.ensure_future(t_orig, loop=self.loop)
275 loop = asyncio.new_event_loop()
277 fut = asyncio.ensure_future(Aw(coro()), loop=loop)
283 asyncio.ensure_future('ok')
286 loop = asyncio.new_event_loop()
291 asyncio.ensure_future(f, loop=loop)
317 T = asyncio.ensure_future(foo(), loop=self.loop)
358 self.assertRaises(asyncio.CancelledError,
435 loop = asyncio.new_event_loop()
464 loop = asyncio.new_event_loop()
493 loop = asyncio.new_event_loop()
496 await asyncio.sleep(10)
511 with self.assertRaises(asyncio.CancelledError):
517 loop = asyncio.new_event_loop()
521 await asyncio.sleep(10)
522 except asyncio.CancelledError:
523 asyncio.current_task().uncancel()
524 await asyncio.sleep(10)
528 loop.run_until_complete(asyncio.sleep(0.01))
535 loop.run_until_complete(asyncio.sleep(0.01))
546 with self.assertRaises(asyncio.CancelledError):
563 # async with asyncio.timeout(1):
572 loop = asyncio.new_event_loop()
575 task = asyncio.current_task()
591 await asyncio.sleep(sleep)
598 and sys.exc_info()[0] is asyncio.CancelledError
635 await asyncio.sleep(0)
673 await asyncio.sleep(10.0)
678 with self.assertRaises(asyncio.CancelledError):
695 loop = asyncio.new_event_loop()
699 await asyncio.sleep(10)
703 await asyncio.sleep(0)
705 done, pending = await asyncio.wait([task])
709 with self.assertRaises(asyncio.CancelledError) as cm:
716 (asyncio.CancelledError, expected_args, 0))
729 loop = asyncio.new_event_loop()
733 await asyncio.sleep(10)
737 await asyncio.sleep(0)
739 done, pending = await asyncio.wait([task])
743 with self.assertRaises(asyncio.CancelledError) as cm:
750 (asyncio.CancelledError, expected_args, 0))
753 loop = asyncio.new_event_loop()
759 await asyncio.sleep(10)
767 except asyncio.CancelledError as ex:
778 (asyncio.CancelledError, ('msg',), 1))
781 loop = asyncio.new_event_loop()
785 await asyncio.sleep(10)
791 done, pending = await asyncio.wait([task])
795 with self.assertRaises(asyncio.CancelledError) as cm:
802 (asyncio.CancelledError, ('my message',), 0))
806 await asyncio.sleep(0)
807 await asyncio.sleep(0)
814 asyncio.CancelledError, self.loop.run_until_complete, t)
829 with self.assertRaises(asyncio.CancelledError):
847 with self.assertRaises(asyncio.CancelledError):
862 except asyncio.CancelledError:
886 except asyncio.CancelledError:
908 loop = asyncio.new_event_loop()
915 await asyncio.sleep(100)
921 asyncio.CancelledError, loop.run_until_complete, t)
929 loop = asyncio.new_event_loop()
940 asyncio.CancelledError, loop.run_until_complete, t)
953 loop = asyncio.new_event_loop()
966 await asyncio.sleep(0)
975 with self.assertRaises(asyncio.CancelledError):
989 loop = asyncio.new_event_loop()
994 await asyncio.sleep(10)
998 await asyncio.sleep(0)
1005 except asyncio.CancelledError:
1007 self.assert_text_contains(tb, "await asyncio.sleep(10)")
1016 loop = asyncio.new_event_loop()
1021 await asyncio.sleep(10)
1025 await asyncio.sleep(0)
1027 done, pending = await asyncio.wait([task])
1033 except asyncio.CancelledError:
1035 self.assert_text_contains(tb, "await asyncio.sleep(10)")
1060 await asyncio.sleep(0.1)
1075 self.assertRaises(asyncio.CancelledError, loop.run_until_complete, t)
1097 a = self.new_task(loop, asyncio.sleep(0.1))
1098 b = self.new_task(loop, asyncio.sleep(0.15))
1101 done, pending = await asyncio.wait([b, a])
1122 asyncio.wait([c, c, self.loop.create_task(coro('spam'))]))
1132 asyncio.wait(set()))
1135 sleep_coro = asyncio.sleep(10.0)
1136 wait_coro = asyncio.wait([sleep_coro], return_when=-1)
1153 a = self.new_task(loop, asyncio.sleep(10.0))
1154 b = self.new_task(loop, asyncio.sleep(0.1))
1157 asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED))
1169 loop.run_until_complete(asyncio.wait([a, b]))
1176 await asyncio.sleep(0)
1179 await asyncio.sleep(0)
1180 await asyncio.sleep(0)
1186 asyncio.wait([b, a], return_when=asyncio.FIRST_COMPLETED))
1205 a = self.new_task(loop, asyncio.sleep(10.0))
1213 asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION))
1222 loop.run_until_complete(asyncio.wait([a, b]))
1236 a = self.new_task(loop, asyncio.sleep(10.0))
1239 await asyncio.sleep(0.01)
1243 task = asyncio.wait([b, a], return_when=asyncio.FIRST_EXCEPTION)
1252 loop.run_until_complete(asyncio.wait([a, b]))
1265 a = self.new_task(loop, asyncio.sleep(0.1))
1268 await asyncio.sleep(0.15)
1274 done, pending = await asyncio.wait([b, a])
1299 a = self.new_task(loop, asyncio.sleep(0.1))
1300 b = self.new_task(loop, asyncio.sleep(0.15))
1303 done, pending = await asyncio.wait([b, a], timeout=0.11)
1312 loop.run_until_complete(asyncio.wait([a, b]))
1327 a = self.new_task(loop, asyncio.sleep(0.1))
1328 b = self.new_task(loop, asyncio.sleep(0.15))
1331 asyncio.wait([b, a], timeout=0.1))
1339 loop.run_until_complete(asyncio.wait([a, b]))
1352 a = self.new_task(loop, asyncio.sleep(0.1))
1353 b = self.new_task(loop, asyncio.sleep(0.15))
1356 done, pending = await asyncio.wait(iter([b, a]))
1381 await asyncio.sleep(dt)
1394 for f in asyncio.as_completed([b, c, a]):
1414 a = loop.create_task(asyncio.sleep(0.1, 'a'))
1415 b = loop.create_task(asyncio.sleep(0.15, 'b'))
1419 for f in asyncio.as_completed([a, b], timeout=0.12):
1425 except asyncio.TimeoutError as exc:
1433 self.assertIsInstance(res[1][1], asyncio.TimeoutError)
1438 loop.run_until_complete(asyncio.wait([a, b]))
1449 a = asyncio.sleep(0.01, 'a')
1452 for f in asyncio.as_completed([a], timeout=1):
1467 a = asyncio.sleep(0.05, 'a')
1468 b = asyncio.sleep(0.10, 'b')
1472 futs = list(asyncio.as_completed(fs))
1494 a = asyncio.sleep(0.05, 'a')
1495 b = asyncio.sleep(0.05, 'b')
1499 futs = list(asyncio.as_completed(fs))
1501 done, pending = await asyncio.wait(
1502 [asyncio.ensure_future(fut) for fut in futs]
1517 for f in asyncio.as_completed([c, c, coro('spam')]):
1534 futs = asyncio.as_completed([a])
1545 futs = list(asyncio.as_completed([coro()]))
1563 await asyncio.sleep(dt/2)
1564 res = await asyncio.sleep(dt/2, arg)
1582 t = self.new_task(loop, asyncio.sleep(10.0, 'yeah'))
1613 await asyncio.sleep(dt)
1620 except asyncio.CancelledError:
1642 asyncio.CancelledError, self.loop.run_until_complete, task)
1666 class Fut(asyncio.Future):
1703 await asyncio.sleep(10)
1710 except asyncio.CancelledError:
1729 self.assertFalse(asyncio.iscoroutinefunction(fn))
1733 self.assertFalse(asyncio.iscoroutinefunction(fn1))
1737 self.assertTrue(asyncio.iscoroutinefunction(fn2))
1739 self.assertFalse(asyncio.iscoroutinefunction(mock.Mock()))
1740 self.assertTrue(asyncio.iscoroutinefunction(mock.AsyncMock()))
1746 self.assertTrue(asyncio.iscoroutinefunction(func))
1749 self.assertTrue(asyncio.iscoroutine(coro))
1770 self.assertIsNone(asyncio.current_task(loop=self.loop))
1773 self.assertIs(asyncio.current_task(), task)
1775 self.assertIs(asyncio.current_task(None), task)
1776 self.assertIs(asyncio.current_task(), task)
1780 self.assertIsNone(asyncio.current_task(loop=self.loop))
1783 self.assertIsNone(asyncio.current_task(loop=self.loop))
1789 self.assertTrue(asyncio.current_task() is task1)
1791 self.assertTrue(asyncio.current_task() is task1)
1795 self.assertTrue(asyncio.current_task() is task2)
1798 self.assertTrue(asyncio.current_task() is task2)
1803 self.loop.run_until_complete(asyncio.wait((task1, task2)))
1804 self.assertIsNone(asyncio.current_task(loop=self.loop))
1818 except asyncio.CancelledError:
1828 except asyncio.CancelledError:
1833 f = asyncio.ensure_future(outer(), loop=self.loop)
1854 d, p = await asyncio.wait([asyncio.create_task(inner())])
1857 f = asyncio.ensure_future(outer(), loop=self.loop)
1861 asyncio.CancelledError, self.loop.run_until_complete, f)
1868 outer = asyncio.shield(inner)
1875 outer = asyncio.shield(inner)
1884 outer = asyncio.shield(inner)
1892 outer = asyncio.shield(inner)
1902 res = self.loop.run_until_complete(asyncio.shield(fut))
1917 await asyncio.shield(inner())
1920 f = asyncio.ensure_future(outer(), loop=self.loop)
1923 with self.assertRaises(asyncio.CancelledError):
1932 parent = asyncio.gather(child1, child2)
1933 outer = asyncio.shield(parent)
1946 inner1 = asyncio.shield(child1)
1947 inner2 = asyncio.shield(child2)
1948 parent = asyncio.gather(inner1, inner2)
1953 self.assertIsInstance(parent.exception(), asyncio.CancelledError)
1967 asyncio.shield(inner)
1974 return asyncio.shield(coro())
1985 asyncio.set_event_loop(self.loop)
1986 self.addCleanup(asyncio.set_event_loop, None)
1987 outer = asyncio.shield(coro())
1997 asyncio.as_completed(fut))
2000 asyncio.as_completed(coro))
2008 asyncio.wait(fut))
2011 asyncio.wait(coro))
2016 asyncio.wait([]))
2034 task = asyncio.ensure_future(coro, loop=self.loop)
2036 self.assertEqual(asyncio.all_tasks(loop=self.loop), {task})
2038 asyncio.set_event_loop(None)
2051 self.assertEqual(asyncio.all_tasks(loop=self.loop), set())
2060 @mock.patch('asyncio.base_events.logger')
2062 loop = asyncio.new_event_loop()
2070 await asyncio.sleep(0.05)
2092 loop = asyncio.new_event_loop()
2101 gather_future = asyncio.gather(child_coro())
2102 return asyncio.ensure_future(gather_future)
2116 # Python issue #26923: asyncio.gather drops cancellation
2131 loop = asyncio.new_event_loop()
2138 await asyncio.gather(asyncio.sleep(0.05),
2145 await asyncio.sleep(0.2)
2151 except asyncio.CancelledError as exc:
2156 (asyncio.CancelledError, expected_args, 0),
2172 await asyncio.sleep(0) # skip one loop iteration
2177 @mock.patch('asyncio.base_events.logger')
2200 self.assertEqual(asyncio.all_tasks(self.loop), set())
2208 # in asyncio.iscoroutine() doesn't break things.
2223 # in asyncio.iscoroutine() doesn't break things.
2234 # in asyncio.iscoroutine() doesn't break things.
2245 task = asyncio.create_task(inner())
2258 task = asyncio.create_task(coro_noop(), name='No-op')
2268 await asyncio.sleep(0.01)
2280 loop = asyncio.new_event_loop()
2309 await asyncio.sleep(0.001)
2312 loop = asyncio.new_event_loop()
2329 await asyncio.sleep(random.uniform(0.001, 0.05))
2338 await asyncio.gather(*tasks)
2340 loop = asyncio.new_event_loop()
2352 await asyncio.sleep(0)
2367 loop = asyncio.new_event_loop()
2380 await asyncio.sleep(0)
2387 t1 = asyncio.create_task(coro(1), context=ctx)
2390 t2 = asyncio.create_task(coro(2), context=ctx)
2395 loop = asyncio.new_event_loop()
2408 await asyncio.sleep(0)
2423 loop = asyncio.new_event_loop()
2433 loop = asyncio.new_event_loop()
2508 await asyncio.sleep(0.1)
2521 with self.assertRaisesRegex(asyncio.InvalidStateError,
2535 await asyncio.sleep(0.1)
2547 with self.assertRaisesRegex(asyncio.InvalidStateError,
2647 class Fut(asyncio.Future):
2656 self.loop = asyncio.new_event_loop()
2686 self.assertEqual(asyncio.all_tasks(loop), set())
2688 self.assertEqual(asyncio.all_tasks(loop), {task})
2702 self.assertEqual(asyncio.all_tasks(loop), set())
2704 self.assertEqual(asyncio.all_tasks(loop), {task})
2718 self.assertEqual(asyncio.all_tasks(loop), set())
2720 self.assertEqual(asyncio.all_tasks(loop), set())
2726 self.assertIsNone(asyncio.current_task(loop))
2728 self.assertIs(asyncio.current_task(loop), task)
2738 self.assertIs(asyncio.current_task(loop), task1)
2746 self.assertIsNone(asyncio.current_task(loop))
2755 self.assertIs(asyncio.current_task(loop), task1)
2763 self.assertIsNone(asyncio.current_task(loop))
2771 self.assertEqual(asyncio.all_tasks(loop), set())
2777 self.assertEqual(asyncio.all_tasks(loop), set())
2803 self.loop = asyncio.new_event_loop()
2810 self.assertIsNone(asyncio.current_task(loop=self.loop))
2814 asyncio.current_task()
2818 self.assertIs(asyncio.current_task(loop=self.loop), task)
2820 self.assertIs(asyncio.current_task(None), task)
2821 self.assertIs(asyncio.current_task(), task)
2825 self.assertIsNone(asyncio.current_task(loop=self.loop))
2845 self.assertTrue(issubclass(asyncio.Task, asyncio.Future))
2939 'import asyncio.coroutines',
2940 'print(asyncio.coroutines._is_debug_mode())'))
2974 return asyncio.gather(*args, **kwargs)
2978 asyncio.gather()
2982 return asyncio.gather()
2984 self.assertIsInstance(fut, asyncio.Future)
2992 asyncio.set_event_loop(self.one_loop)
2993 self.addCleanup(asyncio.set_event_loop, None)
2994 fut = asyncio.gather()
2995 self.assertIsInstance(fut, asyncio.Future)
3005 asyncio.gather(fut1, fut2)
3009 fut = asyncio.gather(*children)
3013 fut = asyncio.gather(*children)
3020 fut = asyncio.gather(a, b, c, d, e)
3029 self.assertIsInstance(fut.exception(), asyncio.CancelledError)
3039 fut = asyncio.gather(a, b, c, d, e, f, return_exceptions=True)
3053 self.assertIsInstance(res[2], asyncio.CancelledError)
3054 self.assertIsInstance(res[4], asyncio.CancelledError)
3072 return asyncio.gather(*args, **kwargs)
3083 asyncio.gather(gen1, gen2)
3091 return asyncio.gather(gen1, gen2)
3100 asyncio.set_event_loop(self.other_loop)
3101 self.addCleanup(asyncio.set_event_loop, None)
3104 fut = asyncio.gather(gen1, gen2)
3126 child1 = asyncio.ensure_future(inner(), loop=self.one_loop)
3127 child2 = asyncio.ensure_future(inner(), loop=self.one_loop)
3132 gatherer = asyncio.gather(child1, child2)
3136 f = asyncio.ensure_future(outer(), loop=self.one_loop)
3139 with self.assertRaises(asyncio.CancelledError):
3159 await asyncio.gather(inner(a), inner(b))
3161 f = asyncio.ensure_future(outer(), loop=self.one_loop)
3171 'asyncio.base_events.BaseEventLoop.call_exception_handler',
3185 """Test case for asyncio.run_coroutine_threadsafe."""
3189 self.loop = asyncio.new_event_loop()
3194 await asyncio.sleep(0.05)
3198 asyncio.current_task(self.loop).cancel()
3199 await asyncio.sleep(0)
3206 future = asyncio.run_coroutine_threadsafe(coro, self.loop)
3238 with self.assertRaises(asyncio.TimeoutError):
3242 for task in asyncio.all_tasks(self.loop):
3250 with self.assertRaises(asyncio.CancelledError):
3285 self.loop = asyncio.new_event_loop()
3303 num = await asyncio.sleep(0, result=10)
3317 self.loop = asyncio.new_event_loop()