Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import asyncio
- g_lock = asyncio.Lock()
- def get_func(i):
- async def func():
- while True:
- async with g_lock:
- print(i)
- await asyncio.sleep(i/10)
- return func
- funcs = [get_func(i) for i in range(3)]
- async def main():
- tasks = [asyncio.create_task(func()) for func in funcs]
- for task in tasks:
- await task
- asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement