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

2024-05-28 20:33:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用txzmqtwisted构建一个侦听器服务,该服务将通过推拉模式处理一些数据。这里有一个工作代码:

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),我可以在以后使用它运行:

^{pr2}$

twistd跑步者一起?在


Tags: 代码fromimportdatatwistedendpointreactor侦听器
1条回答
网友
1楼 · 发布于 2024-05-28 20:33:59

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

只需将ZMQ初始化代码移到实现IService的对象的startService方法中,也许是{}的子类。如果您还想进行适当的清理,那么可以在该类的stopService方法中添加一些清理代码。在

相关问题 更多 >

    热门问题