[Zope] import threading.Lock --> unpickleable

Thomas Guettler zopestoller@thomas-guettler.de
Thu, 18 Apr 2002 15:13:55 +0200


I was told that it is possible to syncronise
several zope-request with methods from the python
library.

But it is not that easy:

If you try to add a threading.Lock() instance to
a python class you get:

Error Type: UnpickleableError
Error Value: Cannot pickle objects

This means, you have to store it in an volatile
attribute. I tried it like this. But this
hangs if I delete the object which has
the Lock as_v_lock instance.


    def acquireLock(self):
         print "StollDMS.acquireLock"
         lock=getattr(self, "_v_lock", None)
         if not lock:
             self._v_lock=threading.Lock()
             lock=self._v_lock
         lock.acquire()

     def releaseLock(self):
         # acquire() should have been called
         # about one second before. This means the volatile lock
         # should still be there
         print "StollDMS.releaseLock"
         self._v_lock.release()

Any ideas?

  thomas