Skip to content

Instantly share code, notes, and snippets.

@lmazuel
Last active July 17, 2017 22:42
Show Gist options
  • Save lmazuel/576a5363e944e01d6bcd3a8a65d472c4 to your computer and use it in GitHub Desktop.
Save lmazuel/576a5363e944e01d6bcd3a8a65d472c4 to your computer and use it in GitHub Desktop.
class AsyncMixin:
async def async_get(self, url):
return "Async download: "+url
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
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