Skip to content

Instantly share code, notes, and snippets.

@mturoci
Created September 20, 2022 16:07
Show Gist options
  • Save mturoci/0a51202946f20fa18ccf99da9c7ad283 to your computer and use it in GitHub Desktop.
Save mturoci/0a51202946f20fa18ccf99da9c7ad283 to your computer and use it in GitHub Desktop.
# Do not run like this - will block the whole thread - freeze the app.
# blocking_function(q, loop)
# Get the current event loop - will be used for
# running async functions within the blocking.
loop = asyncio.get_event_loop()
# Create an event to use for cancellation.
q.client.event = Event()
with concurrent.futures.ThreadPoolExecutor() as pool:
await q.exec(pool, blocking_function, q, loop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment