synchronized method

anton muhin antonmuhin at rambler.ru
Tue Feb 10 11:52:04 CET 2004


Max Ischenko wrote:

> 
> Hi,
> 
> I wrote simple implementation of the "synchronized" methods (a-la Java), 
> could you please check if it is OK:
> 
> def synchronized(method):
> 
>     """
>     Guards method execution, similar to Java's synchronized keyword.
> 
>     The class which uses this method, is required to have a
>     L{threading.Lock} primitive as an attribute named 'lock'.
>     """
> 
>     def wrapper(self, *args):
>         self.lock.acquire()
>         try:
>             return method(self, *args)
>         finally:
>             self.lock.release()
>     return wrapper
> 
> ...I'm no big thread expert
> 
> tia.
> 
> ... The problem is not that there are problems. The problem is expecting 
> otherwise and thinking that having problems is a problem.
>      -- Theodore Rubin

I'd add **kwargs too.

anton.



More information about the Python-list mailing list