summaryrefslogtreecommitdiff
path: root/tests/simult-busy.py
blob: 4cc4b2af98775529c15118fc743ccbdd4efc839c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import asyncio
import time

async def busy_task():
    await asyncio.sleep(3.0)
    return 1

async def main():
    tasks = [asyncio.create_task(busy_task()) for i in range(5)]

    start_time = time.time()
    try:
        # this is to prevent waiting in 'select' all day,
        # which makes the python intepreter not respond to
        # mini-scalene / SCALENE
        while True:
            if time.time() - start_time > 3.5:
                break
            await asyncio.sleep(0)  # yield
    except KeyboardInterrupt:
        pass
    finally:
        print("Done.")

asyncio.run(main())