Metaclasses, decorators, and synchronization

Michael Ekstrand mekstran at scl.ameslab.gov
Sat Sep 24 13:18:04 EDT 2005


I've been googling around for a bit trying to find some mechanism for 
doing in Python something like Java's synchronized methods. In the 
decorators PEP, I see examples using a hypothetical synchronized 
decorator, but haven't stumbled across any actual implementation of 
such a decorator. I've also found Synch.py, but that seems to use 
pre-2.2 metaclasses from what I have read.

Basically, what I want to do is something like this:

class MyClass:
     __metaclass__ = SynchronizedMeta
     @synchronized
     def my_sync_method():
         pass

where SychronizedMeta is some metaclass that implements synchronization 
logic for classes bearing some synchronized decorator (probably also 
defined by the module defining SynchronizedMeta).

After looking in the Cheeseshop, the Python source distribution, and 
Google, I have not been able to find anything that implements this 
functionality. If there isn't anything, that's fine, I'll just write it 
myself (and hopefully be able to put it in the cheeseshop), but I'd 
rather avoid  duplicating effort solving previously solved problems...  
So, does anyone know of anything that alreaady does this? (or are there 
some serious problems with my design?)

TIA,
Michael




More information about the Python-list mailing list