Skip to content

Instantly share code, notes, and snippets.

@cetanu
Created January 15, 2021 03:33
Show Gist options
  • Save cetanu/95649f597a03de44237a5a7719a078b0 to your computer and use it in GitHub Desktop.
Save cetanu/95649f597a03de44237a5a7719a078b0 to your computer and use it in GitHub Desktop.
async.py
from asyncio.events import get_event_loop
from asyncio.tasks import ensure_future, wait
async def run_sync_task(loop, fn, *args):
return await loop.run_in_executor(None, fn, *args)
def greeting(name):
return f'Hello {name}'
loop = get_event_loop()
queue = list()
queue.append(
ensure_future(run_sync_task(loop, greeting, 'bob'))
)
loop.run_until_complete(wait(queue))
for job in queue:
print(job.result())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment