On Tuesday 27 September 2005 00:22, Michele Simionato wrote:
It is not that easy, but you can leverage on my decorator module
which does exactly what you want:
http://www.phyast.pitt.edu/~micheles/python/decorator.zip
Excellent. Thank you :-).
- Michael
--
On Mon, 26 Sep 2005, Jp Calderone wrote:
On Sun, 25 Sep 2005 23:30:21 -0400, Victor Ng [EMAIL PROTECTED] wrote:
You could do it with a metaclass, but I think that's probably overkill.
It's not really efficient as it's doing test/set of an RLock all the
time, but hey - you didn't ask for
On Sep 26, 2005, at 2:16 PM, Tom Anderson wrote:
You could define a meta-lock, and use that to protect the
lock-installation action.
Something like this (not yet tested):
import threading
global_lock = threading.Lock()
def synchronized(meth):
def inner(self, *args, **kwargs):
Michael Ekstrand wrote:
Something like this (not yet tested):
import threading
global_lock = threading.Lock()
def synchronized(meth):
def inner(self, *args, **kwargs):
try:
self._sync_lock.acquire()
except AttributeError:
global_lock.acquire()
On Sep 26, 2005, at 4:21 PM, Scott David Daniels wrote:
Unnecessarily holding a lock while acquiring another can be a nasty
source of deadlock or at least delay. Another source of problems is
holding a lock because an exception skipped past the release code.
I had thought of part of that
Michael Ekstrand ha scritto:
One issue remains in this function: my method's signature is lost when
synchronized is applied (at least as somemeth=synchronized(somemeth);
I'm currently in a 2.3 environment that doesn't have the decorator
syntax, but my understanding is that makes no
You could do it with a metaclass, but I think that's probably overkill.
It's not really efficient as it's doing test/set of an RLock all the
time, but hey - you didn't ask for efficient. :)
1 import threading
2
3 def synchronized(func):
4 def innerMethod(self, *args,
On Sunday 25 September 2005 22:30, Victor Ng wrote:
You could do it with a metaclass, but I think that's probably
overkill.
OK. And thanks for the example :-). It looks simple enough... I didn't
think the solution would be overly complex. And the RLock makes it
easier than I anticipated - was
On Sun, 25 Sep 2005 23:30:21 -0400, Victor Ng [EMAIL PROTECTED] wrote:
You could do it with a metaclass, but I think that's probably overkill.
It's not really efficient as it's doing test/set of an RLock all the
time, but hey - you didn't ask for efficient. :)
There's a race condition in this
Hmmm well that's obvious enough. This is why I shouldn't write code off the cuff on c.l.p :)OTOH - if I just assign the RLock in the base classes initializer, is there any problem?vic
On 9/26/05, Jp Calderone [EMAIL PROTECTED] wrote:
On Sun, 25 Sep 2005 23:30:21 -0400, Victor Ng [EMAIL
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
11 matches
Mail list logo