future.result() freezes in add_done_callback()
See original GitHub issueHi,
below is a simplified example of how calling future.result()
in add_done_callback
freezes.
c = Client()
def sleep():
time.sleep(2)
return 1
def cb(f):
print(f)
print('Result should be {}'.format(sleep()))
print('Result was', f.result())
d = delayed(sleep)()
d.compute() # 1
c.compute(d).result() # 1
f2 = c.compute(d)
f2.add_done_callback(cb)
# <Future: status: finished, type: int, key: finalize-e24717a1ea49f34025d9f69a8d4b9e3e>
# Result should be 1
You never get the f.result()
in cb
. Execution freezes.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
python - ThreadPoolExecutor hangs when call futur result in a ...
I answer to my own question. After investigation, it's simple. I do not shutdown the TheadPoolExecutor and do not use with , then...
Read more >concurrent.futures — Launching parallel tasks — Python 3.11 ...
Signal the executor that it should free any resources that it is using when the currently pending futures are done executing. Calls to...
Read more >Python future interacts badly with stub lifetime #5644 - GitHub
We have problems using Python futures outside of the scope within which they ... function(self.channel, 10) name = response.result().name.
Read more >Class StreamingPullFuture (2.13.11) | Python client library
This future is resolved when the process is stopped (via cancel ) or if it encounters an unrecoverable error. Calling .result() will cause ......
Read more >18.5.3. Tasks and coroutines — Stackless-Python 3.6.13 ...
result() and exception() do not take a timeout argument and raise an exception when the future isn't done yet. Callbacks registered with add_done_callback()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
http://stackoverflow.com/questions/40477518/how-to-get-the-result-of-a-future-in-a-callback/40477862#40477862
Yes,
del f
is what I wish to do in the callback, I was just confused by:So I wasn’t sure if
del f
would work in the callback since e.g.f.result()
would not.