अजगर में प्राप्त करने के लिए, मैं उपयोग कर रहा हूँ निम्नलिखित: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.???????
मुझे कैसे पता क्या पोर्ट चुना जाता है करते हैं? श्रमिकों को पढ़ने के लिए रेडिस में एक लुकअप टेबल होगी।
मैं पुश पुल मॉडल का उपयोग कर रहा हूं। मुझे श्रमिकों को यह जानने की ज़रूरत है कि किन बंदरगाहों से जुड़ना है।
मुझे ऐसा करना है क्योंकि मैं uwsgi में gevent loop का उपयोग कर रहा हूं और एक कांटा के कारण एक सादा अंधा thows और त्रुटि निर्दिष्ट कर रहा हूँ। यदि कोई bind_to_random_port उपयोग करता है तो एक बंदरगाह बंद हो जाता है, मैं बस नहीं जानता कि कौन सा है।
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