Skip to content
Snippets Groups Projects
Commit 3d4ca69f authored by Adrien Béraud's avatar Adrien Béraud
Browse files

python: wait until search completion for blocking get

parent 948a617d
No related branches found
No related tags found
No related merge requests found
...@@ -277,15 +277,19 @@ cdef class DhtRunner(_WithID): ...@@ -277,15 +277,19 @@ cdef class DhtRunner(_WithID):
else: else:
lock = threading.Condition() lock = threading.Condition()
pending = 0 pending = 0
res = []
def tmp_get(v):
nonlocal res
res.append(v)
return True
def tmp_done(ok, nodes): def tmp_done(ok, nodes):
nonlocal pending, lock nonlocal pending, lock
with lock: with lock:
pending -= 1 pending -= 1
lock.notify() lock.notify()
res = []
with lock: with lock:
pending += 1 pending += 1
self.get(key, get_cb=lambda v: res.append(v), done_cb=tmp_done) self.get(key, get_cb=tmp_get, done_cb=tmp_done)
while pending > 0: while pending > 0:
lock.wait() lock.wait()
return res return res
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment