Twisted UDP 服务器 - 守护进程?
我有以下使用 Twisted 的 UDP 服务器:
# init the thread capability
threadable.init(1)
# set the thread pool size
reactor.suggestThreadPoolSize(32)
class BaseThreadedUDPServer(DatagramProtocol):
def datagramReceived(self, datagram, (host, port)):
#do some stuff here...
def main():
reactor.listenUDP(PORT, BaseThreadedUDPServer())
reactor.run()
if __name__ == '__main__':
main()
我希望能够对其进行守护进程,因此根据我所读到的内容,我应该使用 .tac 文件做一些事情,我可以从“twistd -y my_udp_server_file.tac”开始 -问题是我找不到任何有关如何使用此类设置执行此操作的文档。我能找到的只是有关如何守护简单 TCP 回显服务器(即使用 .tac 文件)的示例 - 我需要一个像我拥有的那样的多线程 UDP 服务器。
任何方向将不胜感激。
I have the following UDP server using Twisted:
# init the thread capability
threadable.init(1)
# set the thread pool size
reactor.suggestThreadPoolSize(32)
class BaseThreadedUDPServer(DatagramProtocol):
def datagramReceived(self, datagram, (host, port)):
#do some stuff here...
def main():
reactor.listenUDP(PORT, BaseThreadedUDPServer())
reactor.run()
if __name__ == '__main__':
main()
I would like to be able to daemonize this, so from what I have read I should be doing something with a .tac file that I can start with "twistd -y my_udp_server_file.tac" - the problem is I can't find any documentation on how to do this with this kind of setup. All I can find is examples on how to daemonize simple TCP echo servers (with a .tac file, that is) - I need a multi-threaded UDP server like the one I have.
Any direction would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
Try this:
twistd
中的守护程序代码并不关心您提供的是 UDP 还是 TCP。守护 UDP 服务器的方式与守护 TCP 服务器的方式相同。您应该能够使用 TCP 回显服务器作为示例,为 UDP 服务器编写 .tac 文件。The daemonization code in
twistd
doesn't care if you're serving up UDP or TCP. The way you daemonize a UDP server is identical to the way you daemonize a TCP server. You should be able to use the TCP echo server as an example to write a .tac file for your UDP server.