Usually, each thread has its own data to minimize interference and to localize synchonization in the transaction commit.
However, this makes it difficult to control such data from a single point. E.g. it is very difficult to invalidate cache entries: while there is no problem for a thread to invalidate entries in its own cache, it is very difficult to do the same with the corresponding caches in the other threads.
Shared Resource is a module that manages resources
shared by all threads. Such resources can be controlled
much more easily. A shared resource provides
locking capabilities (via Python's RLock) and performs
automatic locking for function calls.
Access to non-functions is not protected.
A shared resource is identified by an id. The application is responsible that ids are unique.
A call to
returns the resource for id. If such a resource does not yet
exist, one is created
by calling creator with createArguments.
Note, that creator and createArguments should only
depend on id and not any other context, as no
object is created, when a resource for id already
Shared resources are not persistent. Currently, they do not support acquisition. This may change however.
For a while an older version is available here:
This version should be extracted in Zope's installation directory.
Extraction creates the subpackage
SharedResource has been uploaded as "dm.sharedresource" to
the Python package index.
Download the current version from there or even "easy-install" it.