7
在Python中,我使用了以下內容:zeromq和bind_to_random_port - 如何讓端口選擇
context = zmq.Context()
socket = context.socket(zmq.PUSH)
socket.bind_to_random_port('tcp://*', min_port=6001, max_port=6004, max_tries=100)
port_selected = socket.???????
我怎麼知道選擇何種端口?我將有一個查找表中的Redis爲工人閱讀。
我使用的是推拉模型。我需要讓工作人員知道要連接的端口。
我必須這樣做,因爲我使用uwsgi的GEVENT循環並指定一個普通盲thows和錯誤監守叉子。如果使用bind_to_random_port那麼端口seleced,我只是不知道哪個。
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gevent-1.0b2-py2.7-linux-x86_64.egg/gevent/greenlet.py",
line 328, in run
result = self._run(*self.args, **self.kwargs)
File "/home/ubuntu/workspace/rtbopsConfig/rtbServers/rtbUwsgiPixelServer/uwsgiPixelServer.py",
line 43, in sendthis
socket.send(push)
File "/usr/local/lib/python2.7/dist-packages/zmq/green/core.py",
line 173, in send
self._wait_write()
File "/usr/local/lib/python2.7/dist-packages/zmq/green/core.py",
line 108, in _wait_write
assert self.__writable.ready(), "Only one greenlet can be waiting
on this event"
AssertionError: Only one greenlet can be waiting on this event
<Greenlet at 0x2d41370: sendthis('2012-07-02 04:05:15')> failed with
AssertionError
參考:http://zeromq.github.com/pyzmq/api/zmq.html#zmq.Socket.bind_to_random_port – odigity 2013-03-26 13:43:12