Reputation: 336
I would like to debug a Twisted Application in PyCharm
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)
How to run app from command line I know, but how to start debugging in PyCharm can't understand
Upvotes: 2
Views: 1715
Reputation: 4798
Create a new Run Configuration in PyCharm, under the "Python" section.
If you start this application using twistd
, then configure the "Script" setting to point to that twistd, and the "script parameters" as you would have them on the command line. You'll probably want to include the --nodaemon
option.
You should then be able to Run that under PyCharm, or set breakpoints and Debug it.
Upvotes: 2