Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Gregory Ewing Newsgroups: comp.lang.python Subject: Re: [Python-ideas] How the heck does async/await work in Python 3.5 Date: Thu, 25 Feb 2016 10:00:29 +1300 Lines: 22 Message-ID: References: <56c7d145$0$1597$c3e8da3$5496439d@news.astraweb.com> <56CCC98C.5060504@mail.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net AXhz4J8LHvCENpk9uI8rnwGcFnrZIS9zp+iMtEA+8KhmQL6nMt Cancel-Lock: sha1:hn17PFSoMi5ECvCpHtpGZaieDaM= User-Agent: Mozilla Thunderbird 1.0.5 (Macintosh/20050711) X-Accept-Language: en-us, en In-Reply-To: Xref: csiph.com comp.lang.python:103460 王珺 wrote: > 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. Yes, Python can do this, but you probably need to use real threads. The only exception would be if io_operation() were something you could fire off with a single system call that's guaranteed not to block, and then wait for the result later. Opportunities for things like that are rare in unix. (Windows might be different, I'm not sure.) -- Greg