python-zk / kazoo

Kazoo is a high-level Python library that makes it easier to use Apache Zookeeper.
https://kazoo.readthedocs.io
Apache License 2.0
1.3k stars 387 forks source link

can somebody give me example for async? #595

Closed varunajmera0 closed 8 months ago

varunajmera0 commented 4 years ago

from kazoo.client import KazooClient from kazoo.exceptions import NodeExistsError,ConnectionLoss from kazoo.security import ACL, OPEN_ACL_UNSAFE from kazoo.handlers.gevent import SequentialGeventHandler from kazoo.handlers.threading import SequentialThreadingHandler

client = KazooClient(hosts='127.0.0.1:2181', handler=SequentialGeventHandler()) client.start_async()

while True: gevent.sleep(1) print(client.state, 'CONNECTED') client.create_async('/anode', b'fred') print("ok",client.get_async('/anode')[0], 'fred')

error print("ok",client.get_async('/anode')[0], 'fred') TypeError: 'gevent._event.AsyncResult' object is not subscriptable

StephenSorriaux commented 8 months ago

see https://www.gevent.org/api/gevent.event.html#gevent.event.AsyncResult, should be

 print("ok",client.get_async('/anode').get(), 'fred')