Created
January 15, 2021 03:33
-
-
Save cetanu/95649f597a03de44237a5a7719a078b0 to your computer and use it in GitHub Desktop.
async.py
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
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