7

我的生产代码中有很多协程,在处理请求时卡在未知位置。我将带有Python 支持扩展的 gdb 附加到进程,但它没有显示协程中进程卡住的确切行,只显示主堆栈跟踪。这是一个最小的例子:

import asyncio

async def hello():
    await asyncio.sleep(30)
    print('hello world')

asyncio.run(hello())
(gdb) py-bt
Traceback (most recent call first):
  File "/usr/lib/python3.8/selectors.py", line 468, in select
    fd_event_list = self._selector.poll(timeout, max_ev)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 2335, in _run_once
  File "/usr/lib/python3.8/asyncio/base_events.py", line 826, in run_forever
    None, getaddr_func, host, port, family, type, proto, flags)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 603, in run_until_complete
    self.run_forever()
  File "/usr/lib/python3.8/asyncio/runners.py", line 299, in run
  File "main.py", line 7, in <module>

GDB 显示了一个在第 7 行结束的跟踪,但代码显然卡在第 4 行。如何使用嵌套协程使其显示更完整的跟踪?

4

1 回答 1

2

您可以使用aiodebug.log_slow_callbacks.enable(0.05)

关注更多:https ://pypi.org/project/aiodebug/

于 2021-05-27T11:44:21.987 回答