Created
June 25, 2018 18:52
-
-
Save 1st1/8cb311b0a852f342f3f7294e6f1798e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from twisted.internet import asyncioreactor | |
asyncioreactor.install() | |
import treq | |
from twisted.internet.defer import Deferred, ensureDeferred | |
from twisted.internet.task import react | |
async def run(): | |
await treq.get("http://google.com") | |
await Deferred.fromFuture(asyncio.ensure_future(asyncio.sleep(1))) | |
react(lambda x: ensureDeferred(run())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's an idea how to make asyncio Future objects interact with
inlineCallbacks
automagically:with the above patch, the following code just works:
(note that there are no
ensure_future()
andfromFuture()
calls here)