Closed dheerajck closed 4 months ago
I made a minor modification to your code: it now actually does some modicum of computation, and it exits on its own without having to press Ctrl-C.
# async_await.py
import asyncio
def do_something():
a = 1
for i in range(100_000):
a = a * 2
async def task():
print('Task 1')
do_something()
await asyncio.sleep(5)
print('Task 1 done')
async def gather():
print('Gather 1')
asyncio.create_task(task())
print('Gather 1 done')
async def main():
await asyncio.gather(gather())
countdown_timer = 3
while countdown_timer > 0:
print(f"{countdown_timer}...")
await asyncio.sleep(1)
countdown_timer -= 1
print('Main done')
if __name__ == '__main__':
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
When I run it as follows:
python3 -m scalene --cli --cpu test-async.py --reduced-profile
I get the expected results (CPU time for the line doing computation and sleep time for the line waiting):
Python 3.11.6 Scalene version 1.5.38 (2024.03.24)
Profiled values arent in the correct place
To reproduce run this
scalene --cpu-percent-threshold 0 async_await.py --cli
and press Control + C after 3 seconds from when program prints "Task 1 done"output
I would expect some numbers at [1] and [2] is this the intended behaviour when profiling async code with async tasks or is it a bug