Metaclasses, decorators, and synchronization

M

Michael Ekstrand

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top