Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Twisted插件需要在端口被占用时快速失效_Python_Twisted_Twistd - Fatal编程技术网

Python Twisted插件需要在端口被占用时快速失效

Python Twisted插件需要在端口被占用时快速失效,python,twisted,twistd,Python,Twisted,Twistd,我有一个twistd插件,可以监听端口并执行非常简单的操作。问题是,当我启动它时,如果post不可用,它只是在进程运行时坐在那里,但什么也不做。在这种情况下,我需要立即退出该过程,以便更大的系统能够注意到并处理该问题 我有这样的代码: def makeService(options): root = Resource() # Not what I actually have... factory = server.Site(root) server_string = b

我有一个twistd插件,可以监听端口并执行非常简单的操作。问题是,当我启动它时,如果post不可用,它只是在进程运行时坐在那里,但什么也不做。在这种情况下,我需要立即退出该过程,以便更大的系统能够注意到并处理该问题

我有这样的代码:

def makeService(options):
    root = Resource() #  Not what I actually have...
    factory = server.Site(root)
    server_string = b'tcp:{0}:interface={1}'.format(options['port'], options['interface'])
    endpoint = endpoints.serverFromString(reactor, server_string)
    service = internet.StreamServerEndpointService(endpoint, factory)
    return service
这导致:

2016-12-19T11:42:21-0600] [info] [3082] [-] Log opened.
[2016-12-19T11:42:21-0600] [info] [3082] [-] twistd 15.5.0 (/home/matthew/code-venvs/wgcbap/bin/python 2.7.6) starting up.
[2016-12-19T11:42:21-0600] [info] [3082] [-] reactor class: twisted.internet.epollreactor.EPollReactor.
[2016-12-19T11:42:21-0600] [critical] [3082] [-] Unhandled Error
        Traceback (most recent call last):
          File "/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/scripts/_twistd_unix.py", line 394, in startApplication
            service.IService(application).privilegedStartService()
          File "/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/application/service.py", line 278, in privilegedStartService
            service.privilegedStartService()
          File "/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/application/internet.py", line 352, in privilegedStartService
            self._waitingForPort = self.endpoint.listen(self.factory)
          File "/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/internet/endpoints.py", line 457, in listen
            interface=self._interface)
        --- <exception caught here> ---
          File "/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/internet/defer.py", line 121, in execute
            result = callable(*args, **kw)
          File "/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/internet/posixbase.py", line 478, in listenTCP
            p.startListening()
          File "/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/internet/tcp.py", line 984, in startListening
            raise CannotListenError(self.interface, self.port, le)
        twisted.internet.error.CannotListenError: Couldn't listen on 127.0.0.1:9999: [Errno 98] Address already in use.
2016-12-19T11:42:21-0600][info][3082][-]日志已打开。
[2016-12-19T11:42:21-0600][info][3082][-]twistd 15.5.0(/home/matthew/code-venvs/wgcbap/bin/python 2.7.6)正在启动。
[2016-12-19T11:42:21-0600][info][3082][-]反应堆等级:twisted.internet.epollreactor.epollreactor。
[2016-12-19T11:42:21-0600][critical][3082][-]未处理的错误
回溯(最近一次呼叫最后一次):
startApplication中的文件“/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/scripts/_-twistd_-unix.py”,第394行
service.IService(application.privilegedStartService())
privilegedStartService中的文件“/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/application/service.py”,第278行
service.privilegedStartService()
文件“/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/application/internet.py”,第352行,位于privilegedStartService中
self.\u waitingForPort=self.endpoint.listen(self.factory)
文件“/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/internet/endpoints.py”,第457行,在listen中
接口=自身(接口)
---  ---
文件“/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/internet/defer.py”,执行中的第121行
结果=可调用(*参数,**kw)
文件“/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/internet/posixbase.py”,第478行,在listenTCP中
p、 听
文件“/home/matthew/code-venvs/wgcbap/local/lib/python2.7/site-packages/twisted/internet/tcp.py”,第984行,在startListening中
引发CannotListError(self.interface、self.port、le)
twisted.internet.error.CannotListen错误:无法侦听127.0.0.1:9999:[Errno 98]地址已在使用中。
它继续运行,什么也不做

添加一行
服务。_raiseSynchronously=True
就在返回的上方起作用,但似乎没有记录在案,感觉脏兮兮的

有没有一种被认可的方法可以做到这一点