我有一个在 Linux(Ubuntu 18.04)中运行的 Python 脚本,它使用多处理库创建进程,为它们分配要执行的函数。问题是这些功能之一卡住了,我想知道它发生在哪里。我尝试使用python -m trace -l myscript.py,但它无法显示在子流程中执行的功能。虽然下面的脚本不是我使用的脚本,但在尝试跟踪其功能时也会出现这种情况。
import multiprocessing
def print_hello():
print('hello world')
def print_hello_inside_trace():
print('trace: hello world')
def trace_function():
print_hello_inside_trace()
if __name__ == '__main__':
print_hello()
process = multiprocessing.Process(target=trace_function)
process.start()
process.join()
所以,我的问题是:有没有办法跟踪 Python 子进程中执行的代码?另外,出于好奇,是否可以跟踪 Python 线程?

