如何在 PyCharm 中调试扭曲的应用程序
How debuging twisted application in PyCharm
我想在 PyCharm
中调试 Twisted 应用程序
from twisted.internet import defer
from twisted.application import service, internet
from txjason.netstring import JSONRPCServerFactory
from txjason import handler
class Example(handler.Handler):
def __init__(self, who):
self.who = who
@handler.exportRPC("add")
@defer.inlineCallbacks
def _add(self, x, y):
yield
defer.returnValue(x+y)
@handler.exportRPC()
def whoami(self):
return self.who
factory = JSONRPCServerFactory()
factory.addHandler(Example('foo'), namespace='bar')
application = service.Application("Example JSON-RPC Server")
jsonrpcServer = internet.TCPServer(7080, factory)
jsonrpcServer.setServiceParent(application)
如何从命令行 运行 应用程序我知道,但是如何在 PyCharm 中开始调试无法理解
在 PyCharm 的 "Python" 部分下创建一个新的 Run Configuration。
如果您使用 twistd
启动此应用程序,则将 "Script" 设置配置为指向该 twistd,并配置 "script parameters",就像您在命令行上设置的那样。您可能希望包括 --nodaemon
选项。
然后您应该能够 运行 在 PyCharm 或 set breakpoints 下调试它。
我想在 PyCharm
中调试 Twisted 应用程序from twisted.internet import defer
from twisted.application import service, internet
from txjason.netstring import JSONRPCServerFactory
from txjason import handler
class Example(handler.Handler):
def __init__(self, who):
self.who = who
@handler.exportRPC("add")
@defer.inlineCallbacks
def _add(self, x, y):
yield
defer.returnValue(x+y)
@handler.exportRPC()
def whoami(self):
return self.who
factory = JSONRPCServerFactory()
factory.addHandler(Example('foo'), namespace='bar')
application = service.Application("Example JSON-RPC Server")
jsonrpcServer = internet.TCPServer(7080, factory)
jsonrpcServer.setServiceParent(application)
如何从命令行 运行 应用程序我知道,但是如何在 PyCharm 中开始调试无法理解
在 PyCharm 的 "Python" 部分下创建一个新的 Run Configuration。
如果您使用 twistd
启动此应用程序,则将 "Script" 设置配置为指向该 twistd,并配置 "script parameters",就像您在命令行上设置的那样。您可能希望包括 --nodaemon
选项。
然后您应该能够 运行 在 PyCharm 或 set breakpoints 下调试它。