On 7 July 2015 at 06:08, Sven R. Kunze <srku...@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 | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com