From 3d4ca69fb49fc06386eb26ba31d28a367c5b6f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20B=C3=A9raud?= <adrien.beraud@savoirfairelinux.com> Date: Wed, 9 Sep 2015 16:44:07 -0400 Subject: [PATCH] python: wait until search completion for blocking get --- python/opendht.pyx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/opendht.pyx b/python/opendht.pyx index 0cd77a56..7eefb580 100644 --- a/python/opendht.pyx +++ b/python/opendht.pyx @@ -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 -- GitLab