1

我正在尝试使用 pudb 进行多处理调试,但遇到如下错误:

代码:

def worker():
    i = 0
    while i < 10:
        pudb.set_trace()
        i = i + 1
        time.sleep(1)
    
if __name__ == '__main__':
    p1 = multiprocessing.Process(target=worker)
    p1.start()

错误:

File "/usr/local/lib/python2.7/dist-packages/urwid/raw_display.py", line 545, in _getch
    return ord(os.read(self._term_input_file.fileno(), 1))
TypeError: ord() expected a character, but string of length 0 found

有谁知道这个问题?

4

2 回答 2

2

自 pudb 版本2020.1使用pudb.forked.set_trace().

有关类似示例,另请参见https://documen.tician.de/pudb/starting.html#using-the-debugger-after-forking 。

披露:我创作了这个

于 2020-09-21T13:27:31.100 回答
0

如果您使用的是不支持 pudb 的旧版本pudb.forked.set_trace(),您可以使用它pudb.remote.set_trace来调试多处理代码。

这篇文章很好地概述了如何做到这一点:https ://auro-227.medium.com/use-pudb-to-debug-python-multiprocessing-code-c0c5551d010c

于 2021-08-10T14:39:43.213 回答