[Python-ideas] How the heck does async/await work in Python 3.5

王珺 wjun77 at gmail.com
Wed Feb 24 05:40:08 EST 2016


It seems an event loop is required for all async programs in python, but
sometimes I need only lazy i/o. Is it possible with asyncio?


Suppose io_operation() takes 3 seconds, then how can I write something like

future = io_operation()
print('Start')
time.sleep(1)
print('Something')
time.sleep(2)
print(future.result())

that print 'Start' immediately and the result of io_operation() 3 seconds
later. The actual io operations are done by the io device that the main
(and only) thread is not interrupted at all, if my understanding is
correct.

2016-02-24 5:05 GMT+08:00 Sven R. Kunze <srkunze at mail.de>:

> On 20.02.2016 07:53, Christian Gollwitzer wrote:
>
> If you have difficulties wit hthe overall concept, and if you are open to
> discussions in another language, take a look at this video:
>
>
> https://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-39-await-co-routines
>
> MS has added coroutine support with very similar syntax to VC++ recently,
> and the developer tries to explain it to the "stackful" programmers.
>
>
> Because of this thread, I finally finished an older post collecting
> valuable insights from last year discussions regarding concurrency modules
> available in Python:
> http://srkunze.blogspot.com/2016/02/concurrency-in-python.html It appears
> to me that it would fit here well.
>
> @python-ideas
> Back then, the old thread ("Concurrency Modules") was like basically meant
> to result in something useful. I hope the post covers the essence of the
> discussion.
> Some even suggested putting the table into the Python docs. I am unaware
> of the formal procedure here but I would be glad if somebody could point be
> at the right direction if that the survey table is wanted in the docs.
>
> Best,
> Sven
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



More information about the Python-list mailing list