Dev HelpersOpen library
← Back

Coordinate tasks with an event

Coordinate tasks with an event. A self-contained example using the Python standard library.

Open this example in the interactive library

Source code

import asyncio
async def main():
    event = asyncio.Event()
    async def worker():
        await event.wait()
        return 'started'
    task = asyncio.create_task(worker())
    event.set()
    return await task
print(asyncio.run(main()))

Sample output

started