AOP use cases

Will Stuyvesant hwlgw at hotmail.com
Tue Apr 20 04:38:36 EDT 2004


> [Daniel Dittmar]
> class SynchronizedCall:
>     def __init__ (self, lock, method):
>         self.lock = lock
>         self.method = method
> 
>     def __call__ (self, *args, **keywargs):
>         self.lock.acquire ()
>         try:
>             self.method (*args, *keywargs)
>         finally:
>             self.lock.release ()
> 
> obj.append = SynchronizedCall (obj.lock, obj.append)
> # the following calls to obj.append () will be synchronized

That is a nice example.  People (Peter Hansen, me, ...) asked earlier
in this and the previous thread for AOP usage examples/patterns/...
and this is one.

The academic AOP examples I saw could not convince me, but perhaps
somebody who uses AOP-like techniques a lot in practice (not me) can
collect such code examples like the above for something like a Python
aop-module?  I think that would be interesting and possibly highly
useful.

the-size-of-the-python-aop-module-would-convert-more-java-peeps-ly
y'rs  - will



More information about the Python-list mailing list