Skip to content

Instantly share code, notes, and snippets.

@mturoci
Created September 20, 2022 16:13
Show Gist options
  • Save mturoci/8acd2cc9fd76cc2559f2a39c35f623d6 to your computer and use it in GitHub Desktop.
Save mturoci/8acd2cc9fd76cc2559f2a39c35f623d6 to your computer and use it in GitHub Desktop.
# This takes a lot of time (compute heavy).
async def blocking_function(q: Q):
count = 0
total = 20
while count < total:
# Check if cancelled.
if q.client.event.is_set():
await show_cancel(q)
return
# This blocks the main thread and prevents any other execution.
# This would be a heavy compute job in the real world.
time.sleep(1)
count += 1
# Assume you are able to emit some kind of progress.
await update_ui(q, count / total)
# Show a notification at the end.
await show_notification(q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment