What kind of "thread safe" are deque's actually?
Grant Edwards
grant.b.edwards at gmail.com
Mon Mar 27 21:54:30 EDT 2023
On 2023-03-28, Travis Griggs <travisgriggs at gmail.com> wrote:
> A while ago I chose to use a deque that is shared between two threads. I did so because the docs say:
>
> "Deques support thread-safe, memory efficient appends and pops from
> either side of the deque with approximately the same O(1)
> performance in either direction.”
>
> (https://docs.python.org/3.11/library/collections.html?highlight=deque#collections.deque)
>
> Earlier today, looking through some server logs I noticed that from
> time to I’m getting a
>
> RuntimeError: deque mutated during iteration
>
> I guess this surprised me. When I see “thread safe”, I don’t expect
> to get errors.
Well, I guess it doesn't say that iteration of a deque is thread
safe. It only claims that appends and pops from either end are thread
safe. It doesn't even claim that inserts, removes, clear, copy, or any
other operations are thread-safe.
--
Grant
More information about the Python-list
mailing list