Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install dm.sharedresource

How to install dm.sharedresource

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install dm.sharedresource
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
1.0 Available View build log
Windows (64-bit)
1.0 Available View build log
Mac OS X (10.5+)
1.0 Available View build log
Linux (32-bit)
1.0 Available View build log
Linux (64-bit)
1.0 Available View build log
 
Author
License
BSD (see "dm/sharedresource/LICENSE.txt", for deta
Lastest release
version 1.0 on Jan 5th, 2011

A shared resource is some resource identified by an id and used concurrently by several threads. To make the concurrent use safe, calls to resource methods are synchronized.

A resource is obtained by a call to get_resource. The required resource is identified by an id (an arbitrary object adequate as a dictionary key). If a resouce of this id already exists, it is returned. Otherwise, one is created calling the creator and the creator parameters provided to get_resource. The returned value is a wrapper around the resource. The wrapping ensures that calls to the resource's methods are synchronized.

>>> from dm.sharedresource import get_resource
>>> r = get_resource(1, dict) # a new resource is created with the `dict` creator
>>> r is get_resource(1, dict)
True

The resource behaves quite like the created object. However, calls to its methods are synchronized (i.e. thread safe). However, special methods (those the names of which start and and in __) may not be found (Python 2.4 introduced that some methods must be defined at class creation time and are not longer looked up in the instance). As a special case, __getitem__, __setitem__, __delitem__, __len__, __nonzero__ are explicitely delegated.

>>> r[1] = 1
>>> r[1]
1

Parameters and keyword parameters for the creator can be provided as arguments to get_resource.

>>> r = get_resource('with args', dict, {1:1}, a='a', b='b')
>>> sorted(r.items())
[(1, 1), ('a', 'a'), ('b', 'b')]

Now look that normal classes work as creators, too.

>>> class Resource:
...   def __init__(self, v): self.v = v
...   def f(self): return self.v
...
>>> r = get_resource('class', Resource, 1)
>>> r.f()
1

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.