473,543 Members | 2,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Intercepting method calls

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
2 1951
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1353
by: Fenix | last post by:
I want intercept the call to a object method or object property . Its plausible ? Are there any event fired when i invoke a object method or property ?
8
2247
by: Peter Olcott | last post by:
Is there any way to intercept system calls to windows such as TextOut and DrawText? what kinds of system calls can be intercepted, and what is the mechanism to accomplish this?
6
1786
by: Valery Polyakov | last post by:
I am drawing lines with a semi-transparent color (alpha=100). When these lines intercept, the color becomes more intense. Is there a way to avoid this, so that I would get the same intensity of color? Thanks a lot.
5
1760
by: sk | last post by:
Hi, I'm trying to override the Render method of my Page class. Are there any standard guidelines for this? Thanks. Shardul
2
1648
by: Microsoft Newsserver | last post by:
Hi, I am using VS2005/.Ajax 1.1 . I need to mask the screen during async calls back to the server. I can do this by surrounding the whole screen with a filtered div to prevent click throughs to controls. The issue is how or when to turn the filter on the div on. Basically, I need to know how to intercept any of the async calls and turn...
0
1043
by: Gabriel Genellina | last post by:
En Thu, 18 Sep 2008 19:24:26 -0300, Robert Dailey <rcdailey@gmail.com> escribió: Why don't you try it yourself? You may replace builtins.print with your own function too. It's not exactly the same thing, but given your request "intercepting things send to print() before they're sent to sys.stdout" it may be more adequate. --
8
1633
by: K Viltersten | last post by:
I've seen some people calling a stored procedure on MS SQL Server and intercepting an invalid parameter list by a switch statement, demanding that each of the parameters names is exactly as the one in the procedure that's about to be called. If we let in an invalid parameter, we'll get the following error message. Msg 8145, Level 16,...
0
7412
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7697
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5892
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4900
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3395
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
648
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.