Skip to content

Instantly share code, notes, and snippets.

@nakamuray
Last active April 15, 2016 01:43
Show Gist options
  • Save nakamuray/c0a304cdd102703522d8e145273490c7 to your computer and use it in GitHub Desktop.
Save nakamuray/c0a304cdd102703522d8e145273490c7 to your computer and use it in GitHub Desktop.
from concurrent.futures import Future
fut = Future()
fut.add_done_callback(lambda f: f.result() * 2)
fut.set_result(21)
print(fut.result())
#assert fut.result() == 42
fut = Future()
fut.add_done_callback(lambda f: f.set_result(f.result() * 2))
fut.set_result(21)
print(fut.result())
assert fut.result() == 42
@nakamuray
Copy link
Author

result:

21
exception calling callback for <Future at 0x7f5111a82400 state=finished returned int>
Traceback (most recent call last):
  File "/usr/x86_64-pc-linux-gnu/lib/python3.5/concurrent/futures/_base.py", line 297, in _invoke_callbacks
    callback(self)
  File "my/wip/t/t1460684048.py", line 11, in <lambda>
    fut.add_done_callback(lambda f: f.set_result(f.result() * 2))
  File "/usr/x86_64-pc-linux-gnu/lib/python3.5/concurrent/futures/_base.py", line 394, in result
    with self._condition:
RecursionError: maximum recursion depth exceeded
91864530440886500823645093538940097344833116097514922329882365469218025966373788775387553434968260608
Traceback (most recent call last):
  File "gistfile1.py", line 15, in <module>
    assert fut.result() == 42
AssertionError

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment