zc.monitor插件用于调试运行中的进程
项目描述
zc.montorpdb是zc.monitor系统(非常轻量)的一个小型插件。它允许用户telnet到监控端口并调用Python调试器(PDB)提示符。
要使用它,必须首先注册该命令,以便zc.monitor了解它。
>>> import zc.monitorpdb >>> import zope.component >>> import zc.monitor.interfaces >>> zope.component.provideUtility(zc.monitorpdb.command, ... zc.monitor.interfaces.IMonitorPlugin, 'pdb')
由于zc.monitor是用zc.ngi实现的,我们可以使用zc.ngi的测试助手。
>>> import zc.ngi.testing >>> connection = zc.ngi.testing.TextConnection() >>> server = zc.monitor.Server(connection)
如果我们调用命令,我们会得到适当的提示。
>>> connection.test_input('pdb\n')
(Pdb)
现在我们可以做正常的pdb事情,比如列出正在执行的代码。
>>> connection.test_input('l\n')
34 global fakeout
35
36 fakeout = FakeStdout(connection.connection)
37 debugger = pdb.Pdb(stdin=None, stdout=fakeout)
38 debugger.reset()
39 -> debugger.setup(sys._getframe(), None)
40
41
42 def command(connection, *args):
43 global debugger
44 global fakeout
(Pdb)
以及向上进入函数调用栈。
>>> connection.test_input('u\n')
> /graphted-storage/workspace/zc.monitorpdb/src/zc/monitorpdb/__init__.py(48)command()
-> reset(connection)
(Pdb)
有一个“重置”命令,它给我们一个新的调试器(以防我们的调试器出了问题,我们不希望重新启动主机进程)。在这里,我们从当前位置从一个东西(上一个“u”命令的结果)变成另一个。
>>> connection.test_input('l\n')
57 return zc.monitor.QUIT_MARKER
58 else:
59 debugger.onecmd(' '.join(args))
60
61 connection.write(debugger.prompt)
62 -> return zc.monitor.MORE_MARKER
[EOF]
(Pdb)
>>> connection.test_input('reset\n')
(Pdb)
>>> connection.test_input('l\n')
34 global fakeout
35
36 fakeout = FakeStdout(connection.connection)
37 debugger = pdb.Pdb(stdin=None, stdout=fakeout)
38 debugger.reset()
39 -> debugger.setup(sys._getframe(), None)
40
41
42 def command(connection, *args):
43 global debugger
44 global fakeout
(Pdb)
然而,一些功能无法使用。
>>> connection.test_input('debug 1+1\n')
the "debug" command is not supported
(Pdb)
完成后,我们请求让我们离开。
>>> connection.test_input('quit\n')
-> CLOSE
项目详情
关闭
zc.monitorpdb-1.0.0.tar.gz的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 5ca84dd05e30cf8485c922526442cf701fee9e67349dd469efdd85040d9f6a55 |
|
| MD5 | 6fa47b2283cfe09d4ad9c9efbb3cf386 |
|
| BLAKE2b-256 | 8fe993db80c1bcdcf849e5aa0e6781c68ad85f4411416badf743593f26d80896 |