Promises stuck
jhakonen opened this issue · 2 comments
Hi,
I took the promise 2.0b1 into use, but I ran into a bug where the promises stop working after a rejection. Any .then() handlers just refuse to trigger.
Even something as simple as this does not work:
from __future__ import print_function
...
Promise.resolve(None).then(lambda x: print("Hello World"))
However, I managed to reproduce the bug with your test suite.
I added following test to tests/test_issues.py:
def test_my_issue():
context = {"success": False}
promise1 = Promise(lambda resolve, reject: context.update({"promise1_reject": reject}))
promise1.then(lambda x: None)
promise1.then(lambda x: None)
context["promise1_reject"](RuntimeError("Ooops!"))
promise2 = Promise(lambda resolve, reject: context.update({"promise2_resolve": resolve}))
promise2.then(lambda x: context.update({"success": True}))
context["promise2_resolve"](None)
assert context["success"]
Running test suite:
py.test tests --cov=promise --benchmark-skip -s
============================= test session starts =============================
platform win32 -- Python 2.7.10, pytest-3.0.7, py-1.4.33, pluggy-0.4.0
benchmark: 3.0.0 (defaults: timer=time.clock disable_gc=False min_rounds=5 min_time=5.00us max_time=1.00s calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: C:\Tiedostot\Henkilokohtainen\Projektit\World of Tanks\Modit\TessuMod\promise, inifile:
plugins: cov-2.4.0, benchmark-3.0.0
collected 113 items
tests\test_benchmark.py sssssssss
tests\test_complex_threads.py .
tests\test_context.py .....
tests\test_dataloader.py ..............
tests\test_extra.py ............................................
tests\test_issues.py ...F
tests\test_promise_list.py ......
The execution remains stuck in test_promise_list.py, have to kill it with CTRL+C.
If you remove one or both promise1.then(lambda x: None)
lines from the test, the test suite goes through fine without fails nor ending stuck.
Thanks for reporting this and the test case!
I spotted a similar thing recently, I will try to debug and fix it asap :)
Also, if you wanna work on a PR I will happily merge it as well!
That fix indeed fixed the bug I had.
Thank you!