removeall() in list

castironpi at castironpi at
Sat Jan 12 09:37:25 CET 2008

On Jan 11, 8:04 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> castiro... at writes:
> > Could you:
> > lockerA= Locker( listA, listB )
> > lockerA.op( listB.reverse )
> > lockerA.op( listA.pop )
> > Where lockerA ops acquire the locks on all its threads?
> I don't understand that question.  The main thing to understand is
> that multi-threaded programming is complicated (especially if you're
> after high performance), and very difficult to get right without
> knowing exactly what you're doing.  The generally preferred approach
> in Python is to keep things simple at some performance cost.
> Your Locker approach above looks sort of reasonable if you can be
> absolutely sure that nothing else can mess with listA or listB
> concurrently with those locker operations.  Normally you would put
> listA and listB into a single object along with a lock, then do
> operations on that object.
> You might check the Python Cookbook for some specific recipes and
> sample code for this stuff.  If you've used Java, Python's general
> threading mechanisms are similar, but they are in the library rather
> than built into the language (i.e. there is no "synchronized"
> keyword, you have to do that locking explicitly).
> What is the actual application, if you don't mind saying?  Are you
> sure that you really need concurrency?

I'm writing an NxN observer pattern, mostly for my own personal
exploration.  Two threads -might- be calling 'Disconnect' at the same
time, and I can't even guarantee that the function runs properly.

	for emelem in [ e for e in emlist if e.func is func ]:
			emlist.remove( emelem )
		except ValueError:

More information about the Python-list mailing list