Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: =?UTF-8?B?546L54+6?= Newsgroups: comp.lang.python Subject: Re: [Python-ideas] How the heck does async/await work in Python 3.5 Date: Thu, 25 Feb 2016 08:40:44 +0800 Lines: 37 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 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de hP4QPc20yOPHD9fumbUSnwOS3qDSnqBLVHj6MSgCIrZw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:: [': 0.03; 'subject:Python': 0.05; 'subject:How': 0.09; 'specific.': 0.09; 'threads.': 0.09; 'python': 0.10; 'exception': 0.13; '(windows': 0.16; 'async': 0.16; 'different,': 0.16; 'exploits': 0.16; 'gregory': 0.16; 'low-level': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'seconds,': 0.16; 'subject:ideas': 0.16; 'thread.': 0.16; 'wrote:': 0.16; 'subject:] ': 0.19; 'greg': 0.22; 'suppose': 0.22; 'header:In-Reply-To:1': 0.24; 'wonder': 0.27; 'message-id:@mail.gmail.com': 0.27; 'device': 0.28; 'block,': 0.29; 'url:ui': 0.29; "i'm": 0.30; 'print': 0.30; 'subject:/': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'seconds': 0.31; 'probably': 0.31; 'maybe': 0.33; 'source': 0.33; 'url:python': 0.33; 'url:listinfo': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'subject:work': 0.36; 'to:addr:python-list': 0.36; 'things': 0.38; 'received:209': 0.38; 'skip:p 20': 0.38; 'subject:the': 0.39; 'takes': 0.39; 'subject:-': 0.39; 'url:mail': 0.40; 'to:addr:python.org': 0.40; 'future': 0.60; 'real': 0.62; 'details': 0.62; 'fire': 0.63; 'rare': 0.66; 'guaranteed': 0.67; 'url:gstatic': 0.84; 'url:icons': 0.84; 'url:v1': 0.84; 'url:gif': 0.85; 'url:images': 0.85 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=yde9noy90okjSBZlglUxJ0gKJwoBifQ6hJRMCErBeRQ=; b=S79hap5EeYV84h4RoDkKHrrj+ClsWKiWcKQl+gxJbLfqewyw5jt16eEDy1/tjv3i+B TVlxRgh9bJ/WvthqhLtinNyuLbA5wqunWoq28XJSYXQ8AEo+5OwuhMJbeUlex4ZbwsZD JXCP1WVl2w8iHT9Ta4JJYVcqqVDgtdgGZNpLXvyabDyBHhBqPudmbLBY3FO03OMbR/9V DeNFZyoHNmsbHuTbAImJqI38mf6rE/O/XExe4bh3z27JUuUxnj+5ug5hfTpj86RFqLd3 mJliJKtl/TQsBWYZPIE1w4W8gaxq/A9h6g5dzTZcXwjQAsJg9JXw5lRoA6s7zrjAWHmS 9lnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=yde9noy90okjSBZlglUxJ0gKJwoBifQ6hJRMCErBeRQ=; b=S+Gf5GlJHOKv7tsea+LVrXznY3iZNpct4KURNw+OCS1Ex/6e16ASqX6OTWQgwOxNMk UElcGOInp2pzeVfc0MmTpBFwli7VTbX2wz+4qhwAufK7dX2iucgNUuoFMtEBF7JPGo2G 8mTrMJXRqK6s+0NVgLGk2JRSBFOQBac5XEhFNLDCvSzA4Mf4Q74jZgdP1Zg8au2FfkF3 1B5xZA4mC3IBve1Ued+Alv0hWJG3lypNKc9NabrdHpY6XQ413BfyP7alKlbaHO46VcW9 6Yq2DymIOJComy1BdxUZTyTkqttMKq5sT8SYj0ptYx7ezvGis6He3Apzs0lUi2trN0Hl icgw== X-Gm-Message-State: AG10YOSHZw4y7OmkF5w78fgKNtG1/Vj92DLdJ4IBb/MR+caRPqx7jquAj8cj7IJ5mNQcVWJ1DTBsk2SoPbWyEQ== X-Received: by 10.112.138.197 with SMTP id qs5mr15567596lbb.44.1456360844606; Wed, 24 Feb 2016 16:40:44 -0800 (PST) In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.21rc2 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21rc2 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103468 I think this is possible if I understand what happens under the hood. I wonder how event loop and async io functions such as asyncio.open_connection cooperate to do async io in one thread. Maybe it exploits low-level details and is OS or even device specific. I think I should take a look at the source code when I have time. 2016-02-25 5:00 GMT+08:00 Gregory Ewing : > =E7=8E=8B=E7=8F=BA wrote: > >> Suppose io_operation() takes 3 seconds, then how can I write something >> like >> >> future =3D 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 second= s >> 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 > -- > https://mail.python.org/mailman/listinfo/python-list >