question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

future.result() freezes in add_done_callback()

See original GitHub issue

Hi,

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:closed
  • Created 7 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
jlintusaaricommented, Nov 10, 2016

Yes, del f is what I wish to do in the callback, I was just confused by:

pitrou commented 3 hours ago del f would probably be safe, but would also not achieve anything particular.

So I wasn’t sure if del f would work in the callback since e.g. f.result() would not.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found