Are Lists thread safe?

abcd codecraig at gmail.com
Fri Mar 9 15:24:27 EST 2007


On Mar 9, 2:50 pm, "abcd" <codecr... at gmail.com> wrote:
> 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).

comments?




More information about the Python-list mailing list