Skip to content

Instantly share code, notes, and snippets.

@jcfr
Created September 22, 2023 20:10
Show Gist options
  • Save jcfr/e315ac7e5a63327d3ff14a6fc756fb07 to your computer and use it in GitHub Desktop.
Save jcfr/e315ac7e5a63327d3ff14a6fc756fb07 to your computer and use it in GitHub Desktop.
Example of asyncio usage ensuring that printed messages are displayed on-time
import asyncio
import time
def app_print(*args, **kwargs):
print(*args, **kwargs)
slicer.app.processEvents()
async def say_after(delay, what):
await asyncio.sleep(delay)
app_print(what)
async def main():
app_print(f"started at {time.strftime('%X')}")
await say_after(1, 'hello')
await say_after(2, 'world')
app_print(f"finished at {time.strftime('%X')}")
asyncio.run(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment