Created
September 20, 2022 16:13
-
-
Save mturoci/8acd2cc9fd76cc2559f2a39c35f623d6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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