Created
September 22, 2023 20:10
-
-
Save jcfr/e315ac7e5a63327d3ff14a6fc756fb07 to your computer and use it in GitHub Desktop.
Example of asyncio usage ensuring that printed messages are displayed on-time
This file contains 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
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