Infinite loops and synchronization

Aahz aahz at
Tue Jul 14 09:54:07 EDT 2009

In article <mailman.3048.1247462046.8015.python-list at>,
Vincent Gulinao  <vincent.gulinao at> wrote:
>lst = list()
>while True:
>	if len(lst) == SOME_NUMBER:
>		return lst
>Q2: operating on list from threads (mostly appends) must be safe,
>right (synchronization)?

What do you mean by "safe"?  Python certainly won't crash, but there's
no guarantee that the list will be consistent from *your* perspective.
Consider what happens if len(lst) == SOME_NUMBER - 1 and some other part
of your code adds two elements to lst.  You'll skip right over your if
Aahz (aahz at           <*>

"If you think it's expensive to hire a professional to do the job, wait
until you hire an amateur."  --Red Adair

More information about the Python-list mailing list