-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Race condition when waiting on Promise resolved in other thread #87
Comments
What version of Promise are you using? It seems what you commented should be solved in 2.3.0 |
I forked this repository and added test to it. Tag matching release 2.3.0 is there. |
Piggybacking on this issue - I am also getting this error and made sure that I had Promise>=2.3.0 installed prior. Sadly, it is not easily reproducible. The general setting however is the following: I am calling functions using a ThreadPoolExecutor, and each of them returns a Promise. Now, I use Promise.all().then(lambda res: pool.submit(somefunction, res)). This means I am using Promise to handle my threadpool-based Task executing and scheduling. |
Also getting these errors (14 times per 2.5 million requests)
We're executing |
credits to @Novakov at syrusakbary#87
credits to @Novakov at syrusakbary#87
credits to @Novakov at syrusakbary#87
credits to @Novakov at syrusakbary#87
credits to @Novakov at syrusakbary#87
I think I fixed the problem. Review is welcome #89 |
I'm using with LibUsb to achieve asynchronous transfers. Without going into too much details I'm using two threads:
All calls to LibUSB are native calls (
ctypes
).Occasionally (one in hundreds) I'm getting
AssertionFailed
exception on this line: https://github.com/syrusakbary/promise/blob/master/promise/promise.py#L414 with traceback:Traceback indicates that assertion failed in context on Worker thread.
I was able to create (sort of...) reproduction of this issue: https://github.com/Novakov/promise/tree/race-condition Unfortunately it's not great. Running test https://github.com/Novakov/promise/blob/race-condition/tests/test_thread_safety.py#L122 shows the issue in most cases.
Investigation of
Promise
state suggests that in line https://github.com/syrusakbary/promise/blob/master/promise/promise.py#L577 promise is still pending, than context switch happens, promise gets resolved in loop thread, context switch happends again and_add_callbacks
continues on now resolved promise.Machine details
OS: Windows 10 x64
CPU: 4 cores, 8 logical threads
Python: 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]
I was not able to reproduce the issue on Linux machine, however it maybe matter of probability
The text was updated successfully, but these errors were encountered: