In situations like this, you need to guard the resource with a mutex. In Python, things like insertions are atomic but iterations are not. Thusly, if you wrap it with a mutex, things can be made safe. I saw, "can be", because you then have to ensure you always use the mutex to satify your concurrent access requirements.
Greg -- http://mail.python.org/mailman/listinfo/python-list