Circus / ZeroMQ“套接字使用中”错误

时间:2013-11-01 23:03:27

标签: python flask zeromq circusd

我正在运行Flask应用程序并在内部使用Node.js编写的库,我通过ZeroRPC访问(实际的节点进程由Circus管理)。这本身很好用;我可以毫无问题地进行单元测试。但是当启动Flask应用程序作为侦听进程并调用调用此库的REST API时,程序在尝试启动进程时会抛出异常。启动服务的代码如下:

from circus.watcher import Watcher
from circus.arbiter import ThreadedArbiter
from circus.util import (DEFAULT_ENDPOINT_DEALER, DEFAULT_ENDPOINT_SUB,
     DEFAULT_ENDPOINT_MULTICAST)
class Node(object):
    {... omitted code that initializes self._arbiter and self._client ...}
    def start(self):
        if self._arbiter and self._client:
            return
        port = 'ipc:///tmp/inlinejs_%s' % os.getpid()
        args = 'lib/server.js --port %s' % port
        watcher = Watcher('node', '/usr/local/bin/node', args,
            working_dir=INLINEJS_DIR)
        self._arbiter = ThreadedArbiter([watcher], DEFAULT_ENDPOINT_DEALER,
            DEFAULT_ENDPOINT_SUB, multicast_endpoint=DEFAULT_ENDPOINT_MULTICAST)
        self._arbiter.start()
        self._client = zerorpc.Client()
        self._client.connect(port)

此函数返回,但不久之后在另一个线程中,我收到此错误:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/python/lib/python2.7/site-packages/circus/_patch.py", line 21, in _bootstrap_inner
    self.run()
  File "/python/lib/python2.7/site-packages/circus/arbiter.py", line 647, in run
    return Arbiter.start(self)
  File "/python/lib/python2.7/site-packages/circus/util.py", line 319, in _log
    return func(self, *args, **kw)
  File "/python/lib/python2.7/site-packages/circus/arbiter.py", line 456, in start
    self.initialize()
  File "/python/lib/python2.7/site-packages/circus/util.py", line 319, in _log
    return func(self, *args, **kw)
  File "/python/lib/python2.7/site-packages/circus/arbiter.py", line 427, in initialize
    self.evpub_socket.bind(self.pubsub_endpoint)
  File "socket.pyx", line 432, in zmq.core.socket.Socket.bind (zmq/core/socket.c:4022)
  File "checkrc.pxd", line 21, in zmq.core.checkrc._check_rc (zmq/core/socket.c:5838)
ZMQError: Address already in use

我不知道为什么会这样,特别是因为它不会在单元测试中发生。任何人都可以放弃任何光明吗?

1 个答案:

答案 0 :(得分:1)

通常,当您获得此类“正在使用的地址”错误时,这意味着您的程序正在尝试绑定IP端口号,但首先是其他内容。

我不熟悉这个库,但由于错误是由“evpub_socket.bind”引起的,我猜你会发现与常量DEFAULT_ENDPOINT_SUB指定的端口号有冲突。从马戏团源代码中我看到了这些常量:

DEFAULT_ENDPOINT_DEALER =“tcp://127.0.0.1:5555” DEFAULT_ENDPOINT_SUB =“tcp://127.0.0.1:5556” DEFAULT_ENDPOINT_STATS =“tcp://127.0.0.1:5557”

检查您的系统(netstat)并查看是否有任何进程正在侦听端口5555,5556,5557。或者您可能正在运行此程序两次,而您忘记了第一个。