我刚开始使用 Kazoo,我无法运行一个非常简单的程序:
from kazoo.client import KazooClient
import logging
logging.basicConfig(level=logging.DEBUG)
from kazoo.retry import KazooRetry
_retry = KazooRetry(max_tries=1000, delay=0.5, backoff=2)
zk = KazooClient(hosts='164.55.92.8:2181', logger=logging, timeout=10, connection_retry=_retry, read_only=True)
zk.start()
import time
print('sleeping 5!')
time.sleep(5)
zk.stop()
输出如下所示:
ERROR:root:Unhandled exception in connection loop
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\kazoo-2.0-py2.7.egg\kazoo\protocol\connection.py", line 522, in _connect_attempt
[], [], timeout)[0]
File "C:\Python27\lib\site-packages\kazoo-2.0-py2.7.egg\kazoo\handlers\threading.py", line 250, in select
return select.select(*args, **kwargs)
error: (10038, 'An operation was attempted on something that is not a socket')
INFO:root:Zookeeper session lost, state: CLOSED
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 551, in __bootstrap_inner
self.run()
File "C:\Python27\lib\threading.py", line 504, in run
self.__target(*self.__args, **self.__kwargs)
File "C:\Python27\lib\site-packages\kazoo-2.0-py2.7.egg\kazoo\protocol\connection.py", line 466, in zk_loop
if retry(self._connect_loop, retry) is STOP_CONNECTING:
File "C:\Python27\lib\site-packages\kazoo-2.0-py2.7.egg\kazoo\retry.py", line 123, in __call__
return func(*args, **kwargs)
File "C:\Python27\lib\site-packages\kazoo-2.0-py2.7.egg\kazoo\protocol\connection.py", line 483, in _connect_loop
status = self._connect_attempt(host, port, retry)
File "C:\Python27\lib\site-packages\kazoo-2.0-py2.7.egg\kazoo\protocol\connection.py", line 522, in _connect_attempt
[], [], timeout)[0]
File "C:\Python27\lib\site-packages\kazoo-2.0-py2.7.egg\kazoo\handlers\threading.py", line 250, in select
return select.select(*args, **kwargs)
error: (10038, 'An operation was attempted on something that is not a socket')
Traceback (most recent call last):
File "C:\Users\klow\Google Drive\mycode\mykazoo\kazooo.py", line 8, in <module>
zk.start()
File "C:\Python27\lib\site-packages\kazoo-2.0-py2.7.egg\kazoo\client.py", line 537, in start
raise self.handler.timeout_exception("Connection time-out")
TimeoutError: Connection time-out
>>>
我在 Window 7 笔记本电脑上运行它,Zookeeper 服务器在 Linux 机器上运行。看起来 TCP 连接已经建立,之后很快就搞砸了。我稍微研究了一下代码。我可以看到 TCP 连接已在 connection.py:510 (self._connect(host, port)) 处建立,并且 self._socket 已分配给 create_tcp_connection(socket, *args, **kwargs) 返回的对象。但是,connectiom.py:521 处的 self.handle.select() 不喜欢套接字。任何想法?先感谢您!