removeall() in list

castironpi at gmail.com castironpi at gmail.com
Fri Jan 11 19:39:41 EST 2008


On Jan 11, 6:17 pm, castiro... at gmail.com wrote:
> On Jan 11, 5:51 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
>
>
>
> > castiro... at gmail.com writes:
> > > listA.op( insert, x )
> > > listA.op( remove, x )
>
> > Sure, there are various ways you can make the code look uniform.  What
> > gets messy is if you want to (say) operate on several lists at the
> > same time, which means you need to hold multiple locks simultaneously,
> > and some other thread is also trying to do the same thing.  If you
> > acquire the locks in the wrong order, you can get a situation where
> > both threads deadlock forever.
> And:
> > However, in reality, your rock and hard place are:
> > listA.op( listA.insert, x )
> > listA.op( listA.remove, x )
>
> > or
>
> > listA.op( 'insert', x )
> > listA.op( 'remove', x )
>
> For a standard library, you may not want to be exposing the potential
> for deadlock-- not that users can't do that themselves.
>
> lockerA.op( listA.extend, [ x ] )
> lockerB.op( listB.reverse )
> def thA():
>     gui.listbox.append( lockerA.op( listA.pop ) )

Could you:

lockerA= Locker( listA, listB )
lockerA.op( listB.reverse )
lockerA.op( listA.pop )

Where lockerA ops acquire the locks on all its threads?



More information about the Python-list mailing list