On Wed, Feb 25, 2015 at 12:17 PM, Antoine Pitrou <[email protected]>
wrote:

> On Wed, 25 Feb 2015 10:42:23 -0500
> Ben Darnell <[email protected]> wrote:
> > > Maybe we should modify asyncio.Queue and asyncio.Lock to make them
> > > thread-safe?
> > >
> >
> > -1 on modifying asyncio.Lock. You can use a threading.Lock in an asyncio
> > program to protect data that is used by other threads (and if you're
> > concerned about blocking, make your critical sections smaller).
>
> That will stop all coroutines, though, not only the one waiting for the
> lock.
>

Correct; my claim is that this is acceptable for those cases where sharing
mutable state between threads and coroutines is appropriate (which I agree
should be discouraged in general - I'd like for queues to be the most
attractive solution to this problem). Coroutines by their nature block each
other when they do anything at all; as long as you don't do too much while
holding the lock I would expect to incur less blocking by waiting on a lock
than by going through another iteration of the coroutine machinery.

-Ben


> (not that I think trying to synchronize between threads and coroutines
> is a terrific idea)
>
> Regards
>
> Antoine.
>
>
>

Reply via email to