mirror of
https://github.com/savoirfairelinux/opendht.git
synced 2026-11-08 04:21:51 +00:00
python: wait until search completion for blocking get
This commit is contained in:
1 parent
948a617d51
commit
3d4ca69fb4
1 file changed
+6
-2
+6
-2
@@ -277,15 +277,19 @@ cdef class DhtRunner(_WithID):
|
||||
else:
|
||||
lock = threading.Condition()
|
||||
pending = 0
|
||||
res = []
|
||||
def tmp_get(v):
|
||||
nonlocal res
|
||||
res.append(v)
|
||||
return True
|
||||
def tmp_done(ok, nodes):
|
||||
nonlocal pending, lock
|
||||
with lock:
|
||||
pending -= 1
|
||||
lock.notify()
|
||||
res = []
|
||||
with lock:
|
||||
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:
|
||||
lock.wait()
|
||||
return res
|
||||
|
||||
Reference in new issue
Block a user