Skip to content

Instantly share code, notes, and snippets.

@realFranco
Created April 5, 2022 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realFranco/79002d1ff51c7b6635fef6c984bcef13 to your computer and use it in GitHub Desktop.
Save realFranco/79002d1ff51c7b6635fef6c984bcef13 to your computer and use it in GitHub Desktop.
Dont wait for async functions, create tasks and schedule those computations on the same event loop #python #python3 #asyncio #async #io #task #facyt
# Franco Gil
# @realFranco
# April 5th, 2022
class Utils:
@staticmethod
def noBlockCoroutine(coroutine):
try:
# Wrap the coro coroutine into a Task and schedule its execution.
# Return the Task object.
asyncio.create_task(coroutine())
return True
except Exception as err:
print(f'error - At no block corutine: {str(err)}\n')
return False
async def some_awaitable_computation(args: str):
# await computation or some i/o
return 1 + 1
coroutine = some_awaitable_computation(args='CS')
Utils.noBlockCoroutine(coroutine=coroutine)
# continue the workflow
# "some_awaitable_computation" will be scheduled on the same event loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment