List iterator thread safety

Xavier Ho contact at xavierho.com
Thu Aug 27 08:59:51 EDT 2009


On Tue, Aug 25, 2009 at 3:43 AM, Emanuele D'Arrigo <manu3d at gmail.com> wrote:

> Let's say I have a list accessed by two threads, one removing list
> items via "del myList[index]" statement the other iterating through
> the list and printing out the items via "for item in myList:"
> statement.


I tried something similar to that before. Gave me an error. I *think* it was
in compile-time, too, but I might be wrong. The message was something like
that the list size cannot be changed.


> Am I right to say this -won't- generate exceptions because
> the list iterator is not concerned with the list changing in size
> under its nose?


It kind of concerns about the size, I think. If it just checked the "next"
item, that would have been so awesome.


> Or are there pitfalls I should be aware of?


The pitfall is that I don't think it will work at all. At least I haven't
succeeded in doing this in the past.

If you make it work, be sure to share your thoughts =]

Good luck,
-Xav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090827/497f31bc/attachment-0001.html>


More information about the Python-list mailing list