Last active
July 17, 2017 22:42
-
-
Save lmazuel/576a5363e944e01d6bcd3a8a65d472c4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class AsyncMixin: | |
async def async_get(self, url): | |
return "Async download: "+url |
This file contains hidden or 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 sys | |
if sys.version_info >= (3,5,2): | |
# Not executed on old Python, no syntax error | |
from async_mixin import AsyncMixin | |
else: | |
class AsyncMixin: | |
pass | |
class Client(AsyncMixin): | |
def get(self, url): | |
return "Sync download: "+url |
This file contains hidden or 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 client import Client | |
client = Client() | |
# Works anytime | |
content = client.get("urn:test") | |
# Works only if 3.5.2 at least | |
import asyncio | |
loop = asyncio.get_event_loop() | |
loop.run_until_complete(client.async_get("urn:test")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment