1

I am just starting out with Kazoo and I can't get a very simple program to run:

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()

The output is shown below:

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  
>>>   

I am running this on a Window 7 laptop and the Zookeeper server is running on a Linux box. It looks like a TCP connection has been made up something quickly screws up after that. I looked into the code a bit. I can see that the TCP connection has been established at connection.py:510 (self._connect(host, port)) and self._socket has been assigned to object returned by create_tcp_connection(socket, *args, **kwargs). However, self.handle.select() at connectiom.py:521 doesn't like the socket. Any idea? Thank you in advance!

kc66
  • 41
  • 3

1 Answers1

2

I've been investigating this with a similar setup. Win7 + zookeeper running on a linux box. Using Python 3.4. Anyway, I think that this call

s = self.handler.select([self._socket, self._read_pipe],
                                        [], [], timeout)[0]

is attempting to do a select on a pipe. According to the python documentation selects on pipes don't work on Windows. So it appears that kazoo can't work on Windows with the current architecture. I'm messing around with paired sockets in a copy of the code but it isn't looking good.

The fact that kazoo doesn't work with windows clients rather limits its usefulness...

Update: So some hacking around in the kazoo source can solve the problem. I created a small utility function to create a socketpair on Windows. This socket pair emulates a pipe and is returned by the create_pipe function in utils. There are a few places in the client where there are calls to os.read() and os.write() and I replaced them with socket.recv and socket.send and everything appeared to work.

I'm not quite sure why kazoo is using pipes. It seems to be mostly for a signaling function which could be done better with signals. Anyway, I'll checkout the code and see if a more permanent solution can be made.

Ewan Kirk
  • 19
  • 5
  • I took code from https://github.com/python-zk/kazoo/compare/master...iHiroakiKawai:socketpair It works perfectly on Windows 7. – Roman Kh Mar 07 '15 at 21:59