Lines Matching refs:loop

92     def new_task(self, loop, coro, name='TestTask', context=None):
93 return self.__class__.Task(coro, loop=loop, name=name, context=context)
95 def new_future(self, loop):
96 return self.__class__.Future(loop=loop)
100 self.loop = self.new_test_loop()
101 self.loop.set_task_factory(self.new_task)
102 self.loop.create_future = lambda: self.new_future(self.loop)
112 t = self.new_task(self.loop, coro())
120 self.loop.run_until_complete(t)
127 t = self.new_task(self.loop, coro())
133 self.loop.run_until_complete(t)
145 self.loop.run_until_complete(
147 self.new_task(self.loop, run()) for _ in range(100)
160 self.loop.run_until_complete(run(fut))
169 task = asyncio.ensure_future(test(), loop=self.loop)
173 self.loop.run_until_complete(task)
178 t = self.new_task(self.loop, notmuch())
179 self.loop.run_until_complete(t)
182 self.assertIs(t._loop, self.loop)
183 self.assertIs(t.get_loop(), self.loop)
185 loop = asyncio.new_event_loop()
186 self.set_event_loop(loop)
187 t = self.new_task(loop, notmuch())
188 self.assertIs(t._loop, loop)
189 loop.run_until_complete(t)
190 loop.close()
195 t = asyncio.ensure_future(notmuch(), loop=self.loop)
196 self.assertIs(t._loop, self.loop)
197 self.loop.run_until_complete(t)
203 with self.assertRaisesRegex(RuntimeError, 'no current event loop'):
208 t = self.loop.run_until_complete(test())
209 self.assertIs(t._loop, self.loop)
210 self.loop.run_until_complete(t)
215 asyncio.set_event_loop(self.loop)
218 self.assertIs(t._loop, self.loop)
219 self.loop.run_until_complete(t)
224 f_orig = self.new_future(self.loop)
228 self.loop.run_until_complete(f)
233 loop = asyncio.new_event_loop()
234 self.set_event_loop(loop)
237 f = asyncio.ensure_future(f_orig, loop=loop)
239 loop.close()
241 f = asyncio.ensure_future(f_orig, loop=self.loop)
247 t_orig = self.new_task(self.loop, notmuch())
249 self.loop.run_until_complete(t)
254 loop = asyncio.new_event_loop()
255 self.set_event_loop(loop)
258 t = asyncio.ensure_future(t_orig, loop=loop)
260 loop.close()
262 t = asyncio.ensure_future(t_orig, loop=self.loop)
275 loop = asyncio.new_event_loop()
276 self.set_event_loop(loop)
277 fut = asyncio.ensure_future(Aw(coro()), loop=loop)
278 loop.run_until_complete(fut)
286 loop = asyncio.new_event_loop()
287 f = self.new_future(self.loop)
289 'different loop than the one specified as '
290 'the loop argument'):
291 asyncio.ensure_future(f, loop=loop)
292 loop.close()
317 T = asyncio.ensure_future(foo(), loop=self.loop)
320 self.loop.run_until_complete(runner())
323 self.loop.set_debug(False)
344 t = self.new_task(self.loop, gen)
359 self.loop.run_until_complete, t)
366 t = self.new_task(self.loop, notmuch())
367 self.loop.run_until_complete(t)
377 t1 = self.new_task(self.loop, notmuch(), None)
378 t2 = self.new_task(self.loop, notmuch(), None)
388 self.loop.run_until_complete(t1)
389 self.loop.run_until_complete(t2)
395 t = self.new_task(self.loop, notmuch())
398 self.loop.run_until_complete(t)
401 self.loop.set_debug(False)
406 fut = self.new_future(self.loop)
407 task = self.new_task(self.loop, wait_for(fut))
408 test_utils.run_briefly(self.loop)
413 self.loop.run_until_complete(task)
429 self.assertEqual(self.loop.run_until_complete(t), 1042)
435 loop = asyncio.new_event_loop()
436 self.set_event_loop(loop)
445 task = self.new_task(loop, raise_error())
455 task = self.new_task(loop, run())
456 loop.run_until_complete(task)
458 loop.close()
464 loop = asyncio.new_event_loop()
465 self.set_event_loop(loop)
475 task = self.new_task(loop, process_exc(exc))
484 task = self.new_task(loop, run())
485 loop.run_until_complete(task)
487 loop.close()
493 loop = asyncio.new_event_loop()
499 t = self.new_task(loop, task())
512 loop.run_until_complete(t)
514 loop.close()
517 loop = asyncio.new_event_loop()
527 t = self.new_task(loop, task())
528 loop.run_until_complete(asyncio.sleep(0.01))
535 loop.run_until_complete(asyncio.sleep(0.01))
547 loop.run_until_complete(t)
556 loop.close()
572 loop = asyncio.new_event_loop()
576 loop = task.get_loop()
587 timeout_handle = loop.call_later(timeout, on_timeout)
640 t1 = self.new_task(loop, make_request_with_timeout(sleep=10.0, timeout=0.1))
642 loop.run_until_complete(t1)
652 t2 = self.new_task(loop, make_request_with_timeout(sleep=0, timeout=10.0))
654 loop.run_until_complete(t2)
661 loop.close()
670 loop = self.new_test_loop(gen)
676 t = self.new_task(loop, task())
677 loop.call_soon(t.cancel)
679 loop.run_until_complete(t)
695 loop = asyncio.new_event_loop()
696 self.set_event_loop(loop)
702 task = self.new_task(loop, sleep())
708 task = self.new_task(loop, coro())
710 loop.run_until_complete(task)
729 loop = asyncio.new_event_loop()
730 self.set_event_loop(loop)
736 task = self.new_task(loop, sleep())
742 task = self.new_task(loop, coro())
744 loop.run_until_complete(task)
753 loop = asyncio.new_event_loop()
754 self.set_event_loop(loop)
755 fut = loop.create_future()
762 inner_task = self.new_task(loop, sleep())
764 loop.call_soon(inner_task.cancel, 'msg')
770 task = self.new_task(loop, coro())
772 loop.run_until_complete(task)
781 loop = asyncio.new_event_loop()
782 self.set_event_loop(loop)
788 task = self.new_task(loop, sleep())
794 task = self.new_task(loop, coro())
796 loop.run_until_complete(task)
810 t = self.new_task(self.loop, task())
811 test_utils.run_briefly(self.loop) # start coro
814 asyncio.CancelledError, self.loop.run_until_complete, t)
820 f = self.new_future(self.loop)
826 t = self.new_task(self.loop, task())
827 test_utils.run_briefly(self.loop) # start task
830 self.loop.run_until_complete(t)
835 f = self.new_future(self.loop)
841 t = self.new_task(self.loop, task())
842 test_utils.run_briefly(self.loop)
848 self.loop.run_until_complete(t)
855 fut1 = self.new_future(self.loop)
856 fut2 = self.new_future(self.loop)
865 t = self.new_task(self.loop, task())
866 test_utils.run_briefly(self.loop)
869 test_utils.run_briefly(self.loop)
873 res = self.loop.run_until_complete(t)
878 fut1 = self.new_future(self.loop)
879 fut2 = self.new_future(self.loop)
880 fut3 = self.new_future(self.loop)
891 t = self.new_task(self.loop, task())
892 test_utils.run_briefly(self.loop)
895 test_utils.run_briefly(self.loop)
899 test_utils.run_briefly(self.loop)
902 res = self.loop.run_until_complete(t)
908 loop = asyncio.new_event_loop()
909 self.set_event_loop(loop)
918 t = self.new_task(loop, task())
921 asyncio.CancelledError, loop.run_until_complete, t)
929 loop = asyncio.new_event_loop()
930 self.set_event_loop(loop)
937 t = self.new_task(loop, task())
940 asyncio.CancelledError, loop.run_until_complete, t)
953 loop = asyncio.new_event_loop()
954 self.addCleanup(lambda: loop.close())
957 fut = self.new_future(loop)
965 nested_task = self.new_task(loop, nested())
974 task = self.new_task(loop, coro())
976 loop.run_until_complete(task)
989 loop = asyncio.new_event_loop()
990 self.set_event_loop(loop)
997 task = self.new_task(loop, nested())
1002 task = self.new_task(loop, coro())
1004 loop.run_until_complete(task)
1016 loop = asyncio.new_event_loop()
1017 self.set_event_loop(loop)
1024 task = self.new_task(loop, nested())
1030 task = self.new_task(loop, coro())
1032 loop.run_until_complete(task)
1053 loop = self.new_test_loop(gen)
1063 loop.stop()
1065 t = self.new_task(loop, task())
1067 loop.run_until_complete(t)
1069 'Event loop stopped before Future completed.')
1072 self.assertAlmostEqual(0.3, loop.time())
1075 self.assertRaises(asyncio.CancelledError, loop.run_until_complete, t)
1081 task = self.new_task(self.loop, coro())
1084 self.loop.run_until_complete(task)
1095 loop = self.new_test_loop(gen)
1097 a = self.new_task(loop, asyncio.sleep(0.1))
1098 b = self.new_task(loop, asyncio.sleep(0.15))
1106 res = loop.run_until_complete(self.new_task(loop, foo()))
1108 self.assertAlmostEqual(0.15, loop.time())
1111 res = loop.run_until_complete(self.new_task(loop, foo()))
1112 self.assertAlmostEqual(0.15, loop.time())
1119 c = self.loop.create_task(coro('test'))
1121 self.loop,
1122 asyncio.wait([c, c, self.loop.create_task(coro('spam'))]))
1124 done, pending = self.loop.run_until_complete(task)
1131 ValueError, self.loop.run_until_complete,
1138 self.loop.run_until_complete, wait_coro)
1151 loop = self.new_test_loop(gen)
1153 a = self.new_task(loop, asyncio.sleep(10.0))
1154 b = self.new_task(loop, asyncio.sleep(0.1))
1156 loop,
1159 done, pending = loop.run_until_complete(task)
1165 self.assertAlmostEqual(0.1, loop.time())
1168 loop.advance_time(10)
1169 loop.run_until_complete(asyncio.wait([a, b]))
1182 a = self.new_task(self.loop, coro1())
1183 b = self.new_task(self.loop, coro2())
1185 self.loop,
1188 done, pending = self.loop.run_until_complete(task)
1202 loop = self.new_test_loop(gen)
1205 a = self.new_task(loop, asyncio.sleep(10.0))
1210 b = self.new_task(loop, exc())
1212 loop,
1215 done, pending = loop.run_until_complete(task)
1218 self.assertAlmostEqual(0, loop.time())
1221 loop.advance_time(10)
1222 loop.run_until_complete(asyncio.wait([a, b]))
1233 loop = self.new_test_loop(gen)
1236 a = self.new_task(loop, asyncio.sleep(10.0))
1242 b = self.new_task(loop, exc())
1245 done, pending = loop.run_until_complete(task)
1248 self.assertAlmostEqual(0.01, loop.time())
1251 loop.advance_time(10)
1252 loop.run_until_complete(asyncio.wait([a, b]))
1263 loop = self.new_test_loop(gen)
1265 a = self.new_task(loop, asyncio.sleep(0.1))
1271 b = self.new_task(loop, sleeper())
1280 loop.run_until_complete(self.new_task(loop, foo()))
1281 self.assertAlmostEqual(0.15, loop.time())
1283 loop.run_until_complete(self.new_task(loop, foo()))
1284 self.assertAlmostEqual(0.15, loop.time())
1297 loop = self.new_test_loop(gen)
1299 a = self.new_task(loop, asyncio.sleep(0.1))
1300 b = self.new_task(loop, asyncio.sleep(0.15))
1307 loop.run_until_complete(self.new_task(loop, foo()))
1308 self.assertAlmostEqual(0.11, loop.time())
1311 loop.advance_time(10)
1312 loop.run_until_complete(asyncio.wait([a, b]))
1325 loop = self.new_test_loop(gen)
1327 a = self.new_task(loop, asyncio.sleep(0.1))
1328 b = self.new_task(loop, asyncio.sleep(0.15))
1330 done, pending = loop.run_until_complete(
1335 self.assertAlmostEqual(0.1, loop.time())
1338 loop.advance_time(10)
1339 loop.run_until_complete(asyncio.wait([a, b]))
1350 loop = self.new_test_loop(gen)
1352 a = self.new_task(loop, asyncio.sleep(0.1))
1353 b = self.new_task(loop, asyncio.sleep(0.15))
1361 res = loop.run_until_complete(self.new_task(loop, foo()))
1363 self.assertAlmostEqual(0.15, loop.time())
1373 loop = self.new_test_loop(gen)
1375 loop.slow_callback_duration = 1.0
1385 loop.advance_time(0.14)
1398 res = loop.run_until_complete(self.new_task(loop, foo()))
1399 self.assertAlmostEqual(0.15, loop.time())
1412 loop = self.new_test_loop(gen)
1414 a = loop.create_task(asyncio.sleep(0.1, 'a'))
1415 b = loop.create_task(asyncio.sleep(0.15, 'b'))
1421 loop.advance_time(0.02)
1429 res = loop.run_until_complete(self.new_task(loop, foo()))
1434 self.assertAlmostEqual(0.12, loop.time())
1437 loop.advance_time(10)
1438 loop.run_until_complete(asyncio.wait([a, b]))
1447 loop = self.new_test_loop(gen)
1456 loop.run_until_complete(self.new_task(loop, foo()))
1465 loop = self.new_test_loop(gen)
1477 self.assertAlmostEqual(0.05, loop.time())
1478 loop.advance_time(0.05)
1481 self.assertAlmostEqual(0.10, loop.time())
1483 loop.run_until_complete(test())
1506 loop = self.new_test_loop(gen)
1507 loop.run_until_complete(test())
1521 fut = self.new_task(self.loop, runner())
1522 self.loop.run_until_complete(fut)
1535 with self.assertRaisesRegex(RuntimeError, 'no current event loop'):
1539 loop = self.new_test_loop()
1549 loop.run_until_complete(test())
1560 loop = self.new_test_loop(gen)
1567 t = self.new_task(loop, sleeper(0.1, 'yeah'))
1568 loop.run_until_complete(t)
1571 self.assertAlmostEqual(0.1, loop.time())
1580 loop = self.new_test_loop(gen)
1582 t = self.new_task(loop, asyncio.sleep(10.0, 'yeah'))
1585 orig_call_later = loop.call_later
1592 loop.call_later = call_later
1593 test_utils.run_briefly(loop)
1598 test_utils.run_briefly(loop)
1610 loop = self.new_test_loop(gen)
1616 sleeper = self.new_task(loop, sleep(5000))
1617 loop.call_later(0.1, sleeper.cancel)
1626 self.assertEqual(loop.run_until_complete(doer), 'cancelled')
1627 self.assertAlmostEqual(0.1, loop.time())
1630 fut = self.new_future(self.loop)
1635 task = self.new_task(self.loop, coro())
1636 test_utils.run_briefly(self.loop)
1640 test_utils.run_briefly(self.loop)
1642 asyncio.CancelledError, self.loop.run_until_complete, task)
1651 task = self.new_task(self.loop, gen)
1660 self.loop.run_until_complete(task),
1675 fut = Fut(loop=self.loop)
1682 t = self.new_task(self.loop, wait_for_future())
1683 test_utils.run_briefly(self.loop)
1688 test_utils.run_briefly(self.loop)
1700 loop = self.new_test_loop(gen)
1713 task = self.new_task(loop, notmutch())
1714 test_utils.run_briefly(loop)
1719 self.assertRaises(SystemExit, test_utils.run_briefly, loop)
1751 res = self.loop.run_until_complete(coro)
1755 fut = self.new_future(self.loop)
1763 t1 = self.new_task(self.loop, func())
1764 t2 = self.new_task(self.loop, coro())
1765 res = self.loop.run_until_complete(t1)
1770 self.assertIsNone(asyncio.current_task(loop=self.loop))
1772 async def coro(loop):
1778 task = self.new_task(self.loop, coro(self.loop))
1779 self.loop.run_until_complete(task)
1780 self.assertIsNone(asyncio.current_task(loop=self.loop))
1783 self.assertIsNone(asyncio.current_task(loop=self.loop))
1785 fut1 = self.new_future(self.loop)
1786 fut2 = self.new_future(self.loop)
1788 async def coro1(loop):
1794 async def coro2(loop):
1800 task1 = self.new_task(self.loop, coro1(self.loop))
1801 task2 = self.new_task(self.loop, coro2(self.loop))
1803 self.loop.run_until_complete(asyncio.wait((task1, task2)))
1804 self.assertIsNone(asyncio.current_task(loop=self.loop))
1812 waiter = self.new_future(self.loop)
1833 f = asyncio.ensure_future(outer(), loop=self.loop)
1834 test_utils.run_briefly(self.loop)
1836 self.loop.run_until_complete(f)
1844 waiter = self.new_future(self.loop)
1857 f = asyncio.ensure_future(outer(), loop=self.loop)
1858 test_utils.run_briefly(self.loop)
1861 asyncio.CancelledError, self.loop.run_until_complete, f)
1863 test_utils.run_briefly(self.loop)
1867 inner = self.new_future(self.loop)
1870 res = self.loop.run_until_complete(outer)
1874 inner = self.new_future(self.loop)
1876 test_utils.run_briefly(self.loop)
1879 test_utils.run_briefly(self.loop)
1883 inner = self.new_future(self.loop)
1885 test_utils.run_briefly(self.loop)
1887 test_utils.run_briefly(self.loop)
1891 inner = self.new_future(self.loop)
1893 test_utils.run_briefly(self.loop)
1895 test_utils.run_briefly(self.loop)
1900 fut = self.new_future(self.loop)
1902 res = self.loop.run_until_complete(asyncio.shield(fut))
1908 waiter = self.new_future(self.loop)
1920 f = asyncio.ensure_future(outer(), loop=self.loop)
1921 test_utils.run_briefly(self.loop)
1924 self.loop.run_until_complete(f)
1926 test_utils.run_briefly(self.loop)
1930 child1 = self.new_future(self.loop)
1931 child2 = self.new_future(self.loop)
1934 test_utils.run_briefly(self.loop)
1936 test_utils.run_briefly(self.loop)
1940 test_utils.run_briefly(self.loop)
1944 child1 = self.new_future(self.loop)
1945 child2 = self.new_future(self.loop)
1949 test_utils.run_briefly(self.loop)
1952 test_utils.run_briefly(self.loop)
1958 test_utils.run_briefly(self.loop)
1966 with self.assertRaisesRegex(RuntimeError, 'no current event loop'):
1975 outer = self.loop.run_until_complete(test())
1976 self.assertEqual(outer._loop, self.loop)
1977 res = self.loop.run_until_complete(outer)
1985 asyncio.set_event_loop(self.loop)
1988 self.assertEqual(outer._loop, self.loop)
1989 res = self.loop.run_until_complete(outer)
1993 fut = self.new_future(self.loop)
1996 self.assertRaises(TypeError, self.loop.run_until_complete,
1999 self.assertRaises(TypeError, self.loop.run_until_complete,
2004 fut = self.new_future(self.loop)
2007 self.assertRaises(TypeError, self.loop.run_until_complete,
2010 self.assertRaises(TypeError, self.loop.run_until_complete,
2015 self.assertRaises(ValueError, self.loop.run_until_complete,
2021 async def kill_me(loop):
2022 future = self.new_future(loop)
2029 self.loop.set_debug(True)
2030 self.loop.set_exception_handler(mock_handler)
2033 coro = kill_me(self.loop)
2034 task = asyncio.ensure_future(coro, loop=self.loop)
2036 self.assertEqual(asyncio.all_tasks(loop=self.loop), {task})
2041 self.loop._run_once()
2042 self.assertEqual(len(self.loop._ready), 0)
2051 self.assertEqual(asyncio.all_tasks(loop=self.loop), set())
2053 mock_handler.assert_called_with(self.loop, {
2062 loop = asyncio.new_event_loop()
2063 self.set_event_loop(loop)
2069 task = self.new_task(loop, coro())
2074 loop.run_until_complete(runner())
2078 self.loop.set_debug(True)
2080 task = self.new_task(self.loop, coroutine_function())
2087 self.loop.run_until_complete(task)
2092 loop = asyncio.new_event_loop()
2093 self.addCleanup(loop.close)
2095 fut = self.new_future(loop)
2103 gather_task = loop.run_until_complete(create())
2114 loop.run_until_complete(gather_task)
2131 loop = asyncio.new_event_loop()
2132 self.addCleanup(loop.close)
2144 qwe = self.new_task(loop, test())
2150 loop.run_until_complete(main())
2171 task = self.new_task(self.loop, foo())
2172 await asyncio.sleep(0) # skip one loop iteration
2175 self.loop.run_until_complete(main())
2181 self.loop.call_soon = call_soon
2191 self.new_task(self.loop, gen)
2200 self.assertEqual(asyncio.all_tasks(self.loop), set())
2205 self.new_task(self.loop, 123)
2211 self.new_task(self.loop, 123)
2218 task = self.new_task(self.loop, coro())
2220 self.loop.run_until_complete(task)
2224 task = self.new_task(self.loop, coro())
2226 self.loop.run_until_complete(task)
2229 task = self.new_task(self.loop, CoroLikeObject())
2231 self.assertEqual(self.loop.run_until_complete(task), 42)
2235 task = self.new_task(self.loop, CoroLikeObject())
2237 self.assertEqual(self.loop.run_until_complete(task), 42)
2250 self.loop.run_until_complete(coro())
2262 self.loop.run_until_complete(coro())
2274 subtask = self.new_task(loop, sub())
2280 loop = asyncio.new_event_loop()
2282 task = self.new_task(loop, main())
2283 loop.run_until_complete(task)
2285 loop.close()
2299 fut = self.new_future(loop)
2302 loop.call_soon(fut.set_result, None)
2312 loop = asyncio.new_event_loop()
2314 task = self.new_task(loop, main())
2315 loop.run_until_complete(task)
2317 loop.close()
2335 task = loop.create_task(sub(random.randint(0, 10)))
2340 loop = asyncio.new_event_loop()
2342 loop.run_until_complete(main())
2344 loop.close()
2359 t1 = self.new_task(loop, coro(1), context=ctx)
2362 t2 = self.new_task(loop, coro(2), context=ctx)
2367 loop = asyncio.new_event_loop()
2369 task = self.new_task(loop, main())
2370 ret = loop.run_until_complete(task)
2372 loop.close()
2395 loop = asyncio.new_event_loop()
2397 task = self.new_task(loop, main())
2398 ret = loop.run_until_complete(task)
2400 loop.close()
2415 t1 = loop.create_task(coro(1), context=ctx)
2418 t2 = loop.create_task(coro(2), context=ctx)
2423 loop = asyncio.new_event_loop()
2425 task = loop.create_task(main())
2426 ret = loop.run_until_complete(task)
2428 loop.close()
2433 loop = asyncio.new_event_loop()
2436 task = self.new_task(loop, coro)
2437 loop.run_until_complete(task)
2440 loop.close()
2466 fut = self.Future(loop=self.loop)
2469 self.loop.call_soon(lambda: fut.set_result('spam'))
2472 task = self.Task(func(), loop=self.loop)
2474 result = self.loop.run_until_complete(task)
2505 self.loop.call_exception_handler = exc_handler = mock.Mock()
2512 task = self.new_task(self.loop, coro)
2516 self.loop.run_until_complete(task),
2532 self.loop.call_exception_handler = exc_handler = mock.Mock()
2539 task = self.new_task(self.loop, coro)
2543 self.loop.run_until_complete(task)
2568 task = self.new_task(self.loop, coro())
2569 self.loop.run_until_complete(task)
2572 task.__init__(coro(), loop=self.loop)
2573 self.loop.run_until_complete(task)
2579 task = self.new_task(self.loop, coro())
2580 self.loop.run_until_complete(task)
2656 self.loop = asyncio.new_event_loop()
2658 fut = Fut(loop=self.loop)
2659 self.loop.call_later(0.1, fut.set_result, 1)
2660 task = self.loop.create_task(coro())
2661 res = self.loop.run_until_complete(task)
2663 self.loop.close()
2678 return loop
2684 loop = mock.Mock()
2686 self.assertEqual(asyncio.all_tasks(loop), set())
2688 self.assertEqual(asyncio.all_tasks(loop), {task})
2694 return loop
2700 loop = mock.Mock()
2702 self.assertEqual(asyncio.all_tasks(loop), set())
2704 self.assertEqual(asyncio.all_tasks(loop), {task})
2710 return loop
2716 loop = mock.Mock()
2718 self.assertEqual(asyncio.all_tasks(loop), set())
2720 self.assertEqual(asyncio.all_tasks(loop), set())
2725 loop = mock.Mock()
2726 self.assertIsNone(asyncio.current_task(loop))
2727 self._enter_task(loop, task)
2728 self.assertIs(asyncio.current_task(loop), task)
2729 self._leave_task(loop, task)
2734 loop = mock.Mock()
2735 self._enter_task(loop, task1)
2737 self._enter_task(loop, task2)
2738 self.assertIs(asyncio.current_task(loop), task1)
2739 self._leave_task(loop, task1)
2743 loop = mock.Mock()
2744 self._enter_task(loop, task)
2745 self._leave_task(loop, task)
2746 self.assertIsNone(asyncio.current_task(loop))
2751 loop = mock.Mock()
2752 self._enter_task(loop, task1)
2754 self._leave_task(loop, task2)
2755 self.assertIs(asyncio.current_task(loop), task1)
2756 self._leave_task(loop, task1)
2760 loop = mock.Mock()
2762 self._leave_task(loop, task)
2763 self.assertIsNone(asyncio.current_task(loop))
2767 loop = mock.Mock()
2768 task.get_loop = lambda: loop
2771 self.assertEqual(asyncio.all_tasks(loop), set())
2775 loop = mock.Mock()
2777 self.assertEqual(asyncio.all_tasks(loop), set())
2803 self.loop = asyncio.new_event_loop()
2804 self.set_event_loop(self.loop)
2810 self.assertIsNone(asyncio.current_task(loop=self.loop))
2813 with self.assertRaisesRegex(RuntimeError, 'no running event loop'):
2818 self.assertIs(asyncio.current_task(loop=self.loop), task)
2824 self.loop.run_until_complete(task)
2825 self.assertIsNone(asyncio.current_task(loop=self.loop))
2831 return tasks._PyTask(coro, loop=self.loop)
2839 return getattr(tasks, '_CTask')(coro, loop=self.loop)
2874 def _run_loop(self, loop):
2875 while loop._ready:
2876 test_utils.run_briefly(loop)
2977 with self.assertRaisesRegex(RuntimeError, 'no current event loop'):
3082 with self.assertRaisesRegex(RuntimeError, 'no current event loop'):
3126 child1 = asyncio.ensure_future(inner(), loop=self.one_loop)
3127 child2 = asyncio.ensure_future(inner(), loop=self.one_loop)
3136 f = asyncio.ensure_future(outer(), loop=self.one_loop)
3161 f = asyncio.ensure_future(outer(), loop=self.one_loop)
3189 self.loop = asyncio.new_event_loop()
3190 self.set_event_loop(self.loop) # Will cleanup properly
3198 asyncio.current_task(self.loop).cancel()
3204 """Run add coroutine in the event loop."""
3206 future = asyncio.run_coroutine_threadsafe(coro, self.loop)
3213 self.loop.call_soon_threadsafe(coro.send, None)
3220 """Test coroutine submission from a thread to an event loop."""
3221 future = self.loop.run_in_executor(None, self.target)
3222 result = self.loop.run_until_complete(future)
3226 """Test coroutine submission from a thread to an event loop
3228 future = self.loop.run_in_executor(None, self.target, True)
3230 self.loop.run_until_complete(future)
3234 """Test coroutine submission from a thread to an event loop
3237 future = self.loop.run_in_executor(None, callback)
3239 self.loop.run_until_complete(future)
3240 test_utils.run_briefly(self.loop)
3242 for task in asyncio.all_tasks(self.loop):
3246 """Test coroutine submission from a thread to an event loop
3249 future = self.loop.run_in_executor(None, callback)
3251 self.loop.run_until_complete(future)
3254 """Test coroutine submission from a thread to an event loop
3257 def task_factory(loop, coro):
3260 run = self.loop.run_in_executor(
3265 self.loop.set_exception_handler(callback)
3268 self.addCleanup(self.loop.set_task_factory,
3269 self.loop.get_task_factory())
3270 self.loop.set_task_factory(task_factory)
3272 # Run event loop
3274 self.loop.run_until_complete(run)
3278 (loop, context), kwargs = callback.call_args
3285 self.loop = asyncio.new_event_loop()
3286 self.set_event_loop(self.loop)
3289 self.loop.close()
3290 self.loop = None
3301 self.loop.call_soon(inc_result, 1)
3307 self.loop.run_until_complete(coro())
3317 self.loop = asyncio.new_event_loop()
3318 self.set_event_loop(self.loop)
3321 self.loop.close()
3322 self.loop = None