I have the following code snippet:
import asyncio
def main():
asyncio.run(work())
print("BEFORE")
async def work():
await asyncio.sleep(1)
print("AFTER")
main()
I would like "BEFORE" to be printed first, followed by "AFTER" however this prints "AFTER" first instead - have I misunderstood how async functions work? I thought that running asyncio.run(...) would allow my code to skip to print("BEFORE") while still running work() in the background.
Ideal output is:
BEFORE
AFTER
Right now it's
AFTER
BEFORE