[Python-Dev] I'd like list.pop to accept an optional second

M.-A. Lemburg mal@lemburg.com
Fri, 23 Jul 1999 13:07:22 +0200


Christian Tismer wrote:
> 
> "M.-A. Lemburg" wrote:
> ...
> > Also, has anybody considered writing list.pop(..,default) this way:
> >
> > if list:
> >         obj = list.pop()
> > else:
> >         obj = default
> >
> > No exceptions, no changes, fast as hell :-)
> 
> Yes, that's the best way to go, I think.
> But wasn't the primary question directed on
> an atomic function which is thread-safe?
> I'm not sure, this thread has grown too fast :-)

I think that was what Jim had in mind in the first place.
Hmm, so maybe we're not after lists after all: maybe what
we need is access to the global interpreter lock in Python,
so that we can write:

sys.lock.acquire()
if list:
        obj = list.pop()
else:
        obj = default
sys.lock.release()

Or maybe we need some general lock in the thread module for these
purposes... don't know. It's been some time since I used
threads.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Y2000:                                                   162 days left
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/