Re: Are min() and max() thread-safe?

2009-09-17 Thread Miles Kaufmann
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 simultaneously? min() and max() don't release the GIL, so yes, they are safe, and shouldn't see a list in an inconsistent state (with regard

Re: Are min() and max() thread-safe?

2009-09-17 Thread Hrvoje Niksic
Steven D'Aprano ste...@remove.this.cybersource.com.au writes: min() and max() don't release the GIL, so yes, they are safe, and shouldn't see a list in an inconsistent state (with regard to the Python interpreter, but not necessarily to your application). But a threaded approach is somewhat

Re: Are min() and max() thread-safe?

2009-09-17 Thread John Nagle
Steven D'Aprano wrote: 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

Re: Are min() and max() thread-safe?

2009-09-17 Thread Paul McGuire
On Sep 16, 11:33 pm, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: 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

Re: Are min() and max() thread-safe?

2009-09-17 Thread Hendrik van Rooyen
On Thursday 17 September 2009 06:33:05 Steven D'Aprano wrote: 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

Re: Are min() and max() thread-safe?

2009-09-17 Thread Carl Banks
. Are min() and max() thread-safe, or am I doing something fundamentally silly by having them walk over the same list simultaneously? My code is as follows. Is there anything obviously wrong with it? Apart from the plethora of indirection, nothing I can see. But there is something rotten

Re: Are min() and max() thread-safe?

2009-09-17 Thread Carl Banks
On Sep 16, 9:33 pm, Steven D'Aprano ste...@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

Re: Are min() and max() thread-safe?

2009-09-17 Thread Hendrik van Rooyen
On Thursday 17 September 2009 12:57:18 Carl Banks wrote: On Sep 17, 2:18 am, Hendrik van Rooyen hend...@microcorp.co.za wrote: When running min or max on a list of ints, there is probably no occasion for the function to release the GIL. If a thread doesn't release the GIL no other Python

Re: Are min() and max() thread-safe?

2009-09-17 Thread ryles
On Sep 17, 7:02 am, Carl Banks pavlovevide...@gmail.com wrote: On Sep 16, 9:33 pm, Steven D'Aprano ste...@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()    

Are min() and max() thread-safe?

2009-09-16 Thread Steven D'Aprano
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 simultaneously? My

Re: Are min() and max() thread-safe?

2009-09-16 Thread Steven D'Aprano
On Thu, 17 Sep 2009 04:33:05 +, Steven D'Aprano wrote: 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

Re: Are min() and max() thread-safe?

2009-09-16 Thread Miles Kaufmann
On Sep 16, 2009, at 9:33 PM, Steven D'Aprano wrote: 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

Re: Are min() and max() thread-safe?

2009-09-16 Thread Dj Gilcrease
I dont see anything wrong with it and it works for me on a sequence of 5000 -- http://mail.python.org/mailman/listinfo/python-list

Re: Are min() and max() thread-safe?

2009-09-16 Thread Steven D'Aprano
On Wed, 16 Sep 2009 22:08:40 -0700, Miles Kaufmann wrote: On Sep 16, 2009, at 9:33 PM, Steven D'Aprano wrote: 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

Re: Are min() and max() thread-safe?

2009-09-16 Thread Niklas Norrthon
On 17 Sep, 06:33, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: 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