I have a production code that heavily used asyncio.semaphore module which is suspected to have deadlock problem.
I already found some solution of how to attach to running python code with unix signal, debug with ipdb.set_trace()
and list all tasks on event loop with asyncio.Task.all_tasks()
. Can I further inspect into the stack frame of each task or viewing each line of coroutine which is currently pending by futures on ipdb
?
Debug and list all coroutine pending by future in python asyncio
Asked Answered
As OP observes, further inspections may be obtained with
[*map(asyncio.Task.print_stack, asyncio.Task.all_tasks())]
(OP is certainly free to self-answer.)
I have a lot of tasks, all created by the same code, but with different data. I'd like to see which one is the bad one that's still running when my app exits; the stack isn't very helpful to me. Is there any way to give a task a name that will be printed out by str(task) or repr(task)? –
Digitigrade
Well, if you define a class that inherits from Task, then you could certainly add an attribute and override repr so it displays that attribute. –
Snowblind
© 2022 - 2024 — McMap. All rights reserved.
Task.get_stack()
. Maybe this is what you looking for. – Deedeeann[*map(asyncio.Task.print_stack, asyncio.Task.all_tasks())]
works fine. – Swagasyncio.all_tasks()
instead ofasyncio.Task.all_tasks()
asyncio.Task.all_tasks()
is deprecated and will be removed in python 3.9 – Bahaism