小编use*_*039的帖子

Twisted - 使用一个反应器监听多个端口以进行多个进程

我需要在它自己的端口上运行我的服务器应用程序的多个实例.如果我用os.system或subprocess.Popen启动它们不是问题,但是我希望与多处理进行一些进程通信.

我想以某种方式动态设置从不同的进程中侦听不同的端口.只是调用reactor.listenTCP不会这样做,因为我在停止反应堆时变得奇怪的Errno 22.我也很确定这不是正确的做法.我找了一些例子,但找不到任何东西.任何帮助表示赞赏.

编辑:谢谢Tzury,它有点像我想要的.但我必须动态添加端口来监听.例如

from twisted.internet import reactor 
from multiprocessing import Process 

def addListener(self, port, site): 
    ''' Called when I have to add new port to listen to. 
    site - factory handling input, NevowSite in my case''' 
    p = Process(target=f, args=(port, func)) 
    p.start() 

def f(self, port, func): 
    ''' Runs as a new process''' 
    reactor.listenTCP(port, func)
Run Code Online (Sandbox Code Playgroud)

我需要一种方法来整齐地停止这样的过程.只是调用reactor.stop()停止子进程不会这样做.

这是我试图停止进程时遇到的错误

    --- <exception caught here> ---
  File "/usr/share/exe/twisted/internet/tcp.py", line 755, in doRead
    skt, addr = self.socket.accept()
  File "/usr/lib/python2.6/socket.py", line 195, in accept
    sock, addr …
Run Code Online (Sandbox Code Playgroud)

python process twisted

3
推荐指数
1
解决办法
6747
查看次数

标签 统计

process ×1

python ×1

twisted ×1