You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Doc/library/asyncio-dev.rst
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -210,7 +210,7 @@ Example of unhandled exception::
210
210
raise Exception("not consumed")
211
211
212
212
loop = asyncio.get_event_loop()
213
-
asyncio.async(bug())
213
+
asyncio.ensure_future(bug())
214
214
loop.run_forever()
215
215
loop.close()
216
216
@@ -234,7 +234,7 @@ traceback where the task was created. Output in debug mode::
234
234
future: <Task finished coro=<bug() done, defined at test.py:3> exception=Exception('not consumed',) created at test.py:8>
235
235
source_traceback: Object created at (most recent call last):
236
236
File "test.py", line 8, in <module>
237
-
asyncio.async(bug())
237
+
asyncio.ensure_future(bug())
238
238
Traceback (most recent call last):
239
239
File "asyncio/tasks.py", line 237, in _step
240
240
result = next(coro)
@@ -257,14 +257,14 @@ coroutine in another coroutine and use classic try/except::
257
257
print("exception consumed")
258
258
259
259
loop = asyncio.get_event_loop()
260
-
asyncio.async(handle_exception())
260
+
asyncio.ensure_future(handle_exception())
261
261
loop.run_forever()
262
262
loop.close()
263
263
264
264
Another option is to use the :meth:`BaseEventLoop.run_until_complete`
265
265
function::
266
266
267
-
task = asyncio.async(bug())
267
+
task = asyncio.ensure_future(bug())
268
268
try:
269
269
loop.run_until_complete(task)
270
270
except Exception:
@@ -303,14 +303,14 @@ operations::
303
303
304
304
@asyncio.coroutine
305
305
def test():
306
-
asyncio.async(create())
307
-
asyncio.async(write())
308
-
asyncio.async(close())
306
+
asyncio.ensure_future(create())
307
+
asyncio.ensure_future(write())
308
+
asyncio.ensure_future(close())
309
309
yield from asyncio.sleep(2.0)
310
310
loop.stop()
311
311
312
312
loop = asyncio.get_event_loop()
313
-
asyncio.async(test())
313
+
asyncio.ensure_future(test())
314
314
loop.run_forever()
315
315
print("Pending tasks at exit: %s" % asyncio.Task.all_tasks(loop))
316
316
loop.close()
@@ -338,13 +338,13 @@ To fix the example, tasks must be marked with ``yield from``::
338
338
339
339
@asyncio.coroutine
340
340
def test():
341
-
yield from asyncio.async(create())
342
-
yield from asyncio.async(write())
343
-
yield from asyncio.async(close())
341
+
yield from asyncio.ensure_future(create())
342
+
yield from asyncio.ensure_future(write())
343
+
yield from asyncio.ensure_future(close())
344
344
yield from asyncio.sleep(2.0)
345
345
loop.stop()
346
346
347
-
Or without ``asyncio.async()``::
347
+
Or without ``asyncio.ensure_future()``::
348
348
349
349
@asyncio.coroutine
350
350
def test():
@@ -374,7 +374,7 @@ traceback where the task was created. Example of log in debug mode::
374
374
Task was destroyed but it is pending!
375
375
source_traceback: Object created at (most recent call last):
376
376
File "test.py", line 15, in <module>
377
-
task = asyncio.async(coro, loop=loop)
377
+
task = asyncio.ensure_future(coro, loop=loop)
378
378
task: <Task pending coro=<kill_me() done, defined at test.py:5> wait_for=<Future pending cb=[Task._wakeup()] created at test.py:7> created at test.py:15>
0 commit comments