[Python-ideas] PEP 3156 / Tulip: Synchronization primitives
Nikolay Kim
fafhrd91 at gmail.com
Fri Feb 8 01:18:14 CET 2013
I think Tulip should have synchronization primitives by default.
Here is my motivation:
1. it is more convenient to use locking primitive with existing semantics rather than tulip magic.
crawl.py example could use semaphore instead of tasks.wait with timeout 0.
2. while it seems easy to implement semaphore with tulip, it still requires deep understanding of
tulips control flow. i had 2 not very obvious bugs in my semaphore implementation:
a) release() could be called from different co-routines during same scheduling step.
b) bug with acquire and release during same scheduling step.
example:
1. task tries to acquire locked semaphore
2. other task releases semaphore
in result - semaphore gets acquired 2 times at the end of scheduling
step, because actual semaphore acquisition happens in "call_soon" and at this stage
release() call is already released semaphore but first waiter does not acquire it yet.
Thoughts?
my implementation: https://codereview.appspot.com/download/issue7230045_15001.diff
More information about the Python-ideas
mailing list