Are Lists thread safe?

abcd codecraig at gmail.com
Fri Mar 9 14:50:04 EST 2007


I guess this might be overkill then...

class MyList(list):
    def __init__(self):
        self.l = threading.Lock()

    def append(self, val):
        try:
            self.l.acquire()
            list.append(self, val)
        finally:
            if self.l.locked():
                self.l.release()

....performing the same locking/unlocking for the other methods (i.e.
remove, extend, etc).




More information about the Python-list mailing list