Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Marco S." Newsgroups: comp.lang.python Subject: How asyncio works? and event loop vs exceptions Date: Sat, 23 Jul 2016 02:27:44 +0200 Lines: 22 Sender: forwardedby@e4ward.com Message-ID: References: Reply-To: mail.python.org@marco.sulla.e4ward.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de vC7w+i+k0xtAxt6brriiAwV+M33dbTGTxF5oq5pMVjzw== Return-Path: <10921.gmail.com@bounce.e4ward.com> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.105 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'subject:How': 0.09; 'python': 0.10; 'received:io': 0.16; 'received:psf.io': 0.16; 'statement.': 0.16; 'app': 0.16; 'skip:l 30': 0.18; 'exceptions': 0.22; 'programming': 0.22; 'decide': 0.23; 'tried': 0.24; 'switch': 0.27; 'question': 0.27; 'message-id:@mail.gmail.com': 0.27; 'yield': 0.27; 'developing': 0.28; 'cpu': 0.29; 'now?': 0.29; "i'm": 0.30; 'task': 0.30; 'another': 0.32; "can't": 0.32; 'run': 0.33; 'received:google.com': 0.35; 'so,': 0.35; 'header:Received:8': 0.35; 'execution': 0.35; 'tasks': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'possible': 0.36; 'to:addr:python-list': 0.36; 'received:209': 0.38; 'received:209.85.216': 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'skip:n 10': 0.62; 'header:Reply- To:1': 0.67; 'act': 0.67; 'reply-to:no real name:2**0': 0.71; 'contrary': 0.72; 'await': 0.76; 'divergent': 0.84; 'returns.': 0.84; 'imagine': 0.96 Authentication-Results: atl.e4ward.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=e4ward.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=e4ward.com; h= reply-to:content-type:content-type:subject:subject:message-id :date:date:from:from:mime-version; s=mail; t=1469233712; x= 1469320113; bh=Rnnm8q77C3W+Fhz30Qkqz4zdsreg0AwYyzEwX88Oaik=; b=h 5rWEvxcfqiBmH1wnBAqjhpbFUcsPPX1K8PgI0LUjkVLoubpLsg/lUSNvktXDNLIE Y+24/A5K2bOHdXGV7C5enJBjqoGoqKLY7L0Jgrw/f61+RhwUPggh3i0WViDp/PTr XbDIjXTpO+RSfCgu7aPLFeLlk7jgSLqjtTSbI4A2pI= Authentication-Results: atl.e4ward.com (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to; bh=Rnnm8q77C3W+Fhz30Qkqz4zdsreg0AwYyzEwX88Oaik=; b=AlXSDED9jXEL33FZljja5n2PRPYyJjPvsjMeOQGqWSXw9k5X9myffHEfnumXJeJ/wj jhNLj7/U5aOfgM6eYEHmDVUUw/nWPyeybyUyBM5/rMKScJCmSgk/ALDZDdN4zNZLugsp SsvsxqVlpqlKIrEbWkzZlLsac9DYbHxSUZHfDcgS6+UyPZvCpaeYGfjjhFssvNEtVldA oK/AWmTCe7QfEzDfI26YDJjeCiRQa3iU78yyWvhOip4hJNT4mXmt37BTapMFvxfWzCg7 6f5H1rW+/KWOaBIh91Onh9Sm0sLY9F7DwXreuvdSj4IsKVRI0z1FXyrnybVmT6VvoKdC cGCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=Rnnm8q77C3W+Fhz30Qkqz4zdsreg0AwYyzEwX88Oaik=; b=Y3b7f39pUaB2kIPfrYndXcRP7oKtvf9ku5WhmKYrkbElsEo0BQ0WMdqoma60G+mIwW qpWh3d17nfUvl4jMKr5ioVPeFHXpbT1M6+PCfWpERE6FRHcsLan+MjA8EdzQXHjopB7q nbWNRP2/I9R9EBABnzoEPB3/S8/TOaRwac6ql1n1idat4pLdH8lw7uKZlTwJ5qrk/rIj mgPlrDZbL3P6hjwpzPu/PSV+mQHoM6zAlbZ+pWcH88o2Q56Xw08Wa1pRRAW7VguR03XF 0+/782GauVIVTY/XYObOzB85lotBPfkKtMZHaqVOUTATvbYCN1iaWj1djGPtPC6rrfor CBmA== X-Gm-Message-State: AEkoousy4ZfJSEKJqyu88s2cEJCUuxF4Aiy2dB9OZ97GV+sepiANJ57sl2kGR/9qBXWXjPYR5aacXVK0soSojw== X-Received: by 10.200.47.39 with SMTP id j36mr10896067qta.10.1469233704049; Fri, 22 Jul 2016 17:28:24 -0700 (PDT) X-e4ward-RCPT: python-list.python.org-mail.python.org.marco.sulla.e4ward.com@furxh568137.reply.e4ward.com X-e4ward-x: . X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: Xref: csiph.com comp.lang.python:111776 I'm developing a web app based on aiohttp, and I find the event loop concept very interesting. I never programmed with it before, but I know that node.js and GUIs are based on it. What I can't understand is how asyncio make it possible to run multiple tasks concurrently, since it's single threaded (if you don't use loop.run_in_executor()). I just tried to imagine that it should act as a cpu scheduler. Is this true? If so, how and when asyncio decide to switch to another task? Furthermore I have a question about exceptions in asyncio. If I understand well how it works, tasks exceptions can be caught only if you wait for task completion, with yield from, await or loop.run_until_complete(future). But in this case the coroutine blocks the execution of the program until it returns. On the contrary you can execute the coroutine inside an asyncio task and it will be non-blocking, but in this case exceptions can't be caught in a try statement. Is this correct? If so, asyncio programming style can't be a little divergent from what was the philosophy of Python until now?