A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2015-July/140677.html below:

[Python-Dev] Importance of "async" keyword

[Python-Dev] Importance of "async" keyword [Python-Dev] Importance of "async" keywordNick Coghlan ncoghlan at gmail.com
Tue Jul 7 14:40:37 CEST 2015
On 7 July 2015 at 06:08, Sven R. Kunze <srkunze at mail.de> wrote:
> I would like to rewrite/amend it to work asynchronously with minimal effort
> such as:
>
> def business_new():
>     content1 = fork open('big.file').read()  # wraps up the calls into
> awaitables
>     content2 = fork open('huge.file').read() # and put them into the event
> loop
>     return content1 + content2               # variables are used => await
> evaluation
>
> I might have missed something but I think you get my point.

No, you haven't missed anything, but I think the convenience APIs
we're discussing in this thread are what you need, rather than
async/await.

Specifically, your main application would remain synchronous, but the
event loop could be used to run selected operations in a background
thread:

    def business_new():
        future1 = asyncio.call_async(open('big.file').read)
        future2 = asyncio.call_async(open('huge.file').read)
        content1 = asyncio.wait_for_result(future1)
        content2 = asyncio.wait_for_result(future2)
        return content1 + content2

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4