Differences between revisions 1 and 2
Revision 1 as of 2020-04-07 21:42:37
Size: 452
Editor: SamatJain
Comment:
Revision 2 as of 2020-06-23 06:26:39
Size: 1440
Editor: SamatJain
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
== Notes ==

 * `asyncio.run()` gets the event loop, runs tasks until they're complete, and closes the event loop. Introduced in Python 3.7 and replaces `asyncio.get_event_loop()` and `loop.run_until_complete()`. E.g.

{{{#!highlight python numbers=off
asyncio.run(main())
}}}

rather than:

{{{#!highlight python numbers=off
loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.close()
}}}

 * `async.gather` will schedule multiple async tasks at once. Waits for all tasks to be completed, returns list of results.

== Links ==

 * [[https://redislabs.com/blog/async-await-programming-basics-python-examples/|Async/Await Programming Basics with Python Examples for Redis]]: examples of `async.gather()` w/ Redis API

 * [[https://realpython.com/async-io-python/|AsyncIO in Python: A Complete Walkthrough]]: great overview
 * [[https://www.pythonsheets.com/notes/python-asyncio.html|Asyncio PySheeet]]: reference snippets

Notes

  • asyncio.run() gets the event loop, runs tasks until they're complete, and closes the event loop. Introduced in Python 3.7 and replaces asyncio.get_event_loop() and loop.run_until_complete(). E.g.

asyncio.run(main())

rather than:

loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.close()
  • async.gather will schedule multiple async tasks at once. Waits for all tasks to be completed, returns list of results.

SamatsWiki: ProgrammingLanguages/Python/asyncio (last edited 2020-06-28 04:16:00 by SamatJain)