473,805 Members | 1,980 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 1977
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
1370
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
2262
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
1802
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
1786
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
1660
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 the div filter on, which I then turn off again during page load.
0
1058
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
1644
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, State 1, Procedure Prc, Line 0 @Param is not a parameter for procedure Prc.
0
9716
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10607
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10359
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10364
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10104
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7645
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6875
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5541
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.