By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,818 Members | 1,262 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,818 IT Pros & Developers. It's quick & easy.

Intercepting method calls

P: n/a
I want to write a package to simulate a distributed system with objects
at various locations interacting with each other. What I'd like to do is
simulate network delays between distant objects using an event queue.

That is, when I call A.B(foo), I want this call to be intercepted
somehow, and the call to B added to a central event queue thread, and is
called later, possibly after other previously enqued method calls. The
central queue would also do some accounting to keep track of things like
messages sent, message size, etc.

The idea is that you just write these objects as if they were local
objects communicating normally, and all the network simulation is done
for you transparently - perhaps by some 'NetworkObject' superclass.

I took a look at the language reference and it is not immediately clear
to me how or if I could do this in Python, perhaps I need to override
the __call__ methods for all the instancemethods in the class? I'm not
even sure how I could do this... Any help or suggestions appreciated.

Thanks,
Matt
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Matt Leslie wrote:
I took a look at the language reference and it is not immediately clear
to me how or if I could do this in Python, perhaps I need to override
the __call__ methods for all the instancemethods in the class? I'm not
even sure how I could do this... Any help or suggestions appreciated.


A way to accomplish this is the usage of metaclasses. A metaclass gives you
a sort of callback that gets invoked with the classname, the base classes
and the class dictionary before the actual class object is created. Here
you then can creat wrappers around all callables that implement your
desired behaviour.
See this reciepe:

http://aspn.activestate.com/ASPN/Coo.../Recipe/198078
--
Regards,

Diez B. Roggisch
Jul 18 '05 #2

P: n/a
Diez B. Roggisch wrote:
A way to accomplish this is the usage of metaclasses. A metaclass gives you
a sort of callback that gets invoked with the classname, the base classes
and the class dictionary before the actual class object is created. Here
you then can creat wrappers around all callables that implement your
desired behaviour.


Thanks, I'll take a look at that.

Ta,
Matt
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.