Python 如何在twisted应用程序服务中包装zeromq绑定套接字?

Python 如何在twisted应用程序服务中包装zeromq绑定套接字?,python,twisted,zeromq,Python,Twisted,Zeromq,我正在使用txzmq和twisted构建一个侦听器服务,该服务将通过推拉模式处理一些数据。下面是一个工作代码: from txzmq import ZmqFactory, ZmqEndpoint, ZmqPullConnection from twisted.internet import reactor zf = ZmqFactory() endpoint = ZmqEndpoint('bind', 'tcp://*:5050') def onPull(data): # do so

我正在使用
txzmq
twisted
构建一个侦听器服务,该服务将通过推拉模式处理一些数据。下面是一个工作代码:

from txzmq import ZmqFactory, ZmqEndpoint, ZmqPullConnection
from twisted.internet import reactor

zf = ZmqFactory()
endpoint = ZmqEndpoint('bind', 'tcp://*:5050')

def onPull(data):
    # do something with data

puller = ZmqPullConnection(zf, endpoint)
puller.onPull = onPull

reactor.run()
我的问题是-如何将此代码包装到扭曲的应用程序服务中?也就是说,如何将其包装到我以后可以使用的特定服务(例如,
MyService
)中:

from twisted.application.service import Application

application = Application('My listener')
service = MyService(bind_address='*', port=5050)
service.setServiceParent(application)
使用
twistd
runner?

定义服务的含义。是一个基类,在实现新服务时通常很有用

只需将ZMQ初始化代码移动到实现
iSeries设备
的对象的
startService
方法中,可能是
服务
的子类。如果您也想进行适当的清理,那么可以向该类的
stopService
方法添加一些清理代码