Are min() and max() thread-safe?
rylesny at gmail.com
Thu Sep 17 18:49:45 CEST 2009
On Sep 17, 7:02 am, Carl Banks <pavlovevide... at gmail.com> wrote:
> On Sep 16, 9:33 pm, Steven D'Aprano
> <ste... at REMOVE.THIS.cybersource.com.au> wrote:
> > def minmax(seq):
> > result = [None, None]
> > t1 = MMThread(seq, min, result, 0)
> > t2 = MMThread(seq, max, result, 1)
> > t1.start()
> > t2.start()
> > # Block until all threads are done.
> > while any([t1.isAlive(), t2.isAlive()]):
> > time.sleep(0)
> Why not use "t1.join(); t2.join()" here? Is there any benefit to do
> it this way instead?
> Carl Banks
The benefit is that SIGINT (Control-C) will be handled. Not sure why
sleep(0) is used, though, rather than something less busy like sleep
More information about the Python-list