Are min() and max() thread-safe?
steven at REMOVE.THIS.cybersource.com.au
Thu Sep 17 06:33:05 CEST 2009
I have two threads, one running min() and the other running max() over
the same list. I'm getting some mysterious results which I'm having
trouble debugging. Are min() and max() thread-safe, or am I doing
something fundamentally silly by having them walk over the same list
My code is as follows. Is there anything obviously wrong with it?
import threading, time
def __init__(self, data, func, target, where):
self._data = data
self._func = func
self._target = target
self._where = where
self._target[self._where] = self._func(self._data)
result = [None, None]
t1 = MMThread(seq, min, result, 0)
t2 = MMThread(seq, max, result, 1)
# Block until all threads are done.
while any([t1.isAlive(), t2.isAlive()]):
assert None not in result
More information about the Python-list