[Tutor] intercepting and recored I/O function calls

Martin A. Brown martin at linux-ip.net
Fri Sep 17 13:27:41 CEST 2010


Good morning Jojo,

 : Thanks Martin, for the detailed break down, it actually helped me 
 : solve one of my other problems..

Quite glad to help.

 : My applogies to begin with, it seems i didnt state my problem 
 : clearly for this particular case - perharps I/O was not the best 
 : way to describe my problem.
 : 
 : We have a system fully developed in python- with thousands of 
 : lines of code- i know i can use the logging facilty for this 
 : task, but this means i have to go into the code and edit it to 
 : log specifics of what i need, this is gone take a while and this 
 : also implies all other users adding modules must include logging 
 : statements..

Right.  OK.  So, you have an existing code base that you are trying 
to understand (and possibly instrument), got it.

 : Specifically, i would like to track all inputs/output to 
 : modules/functions - if a module retrieved and used files and run 
 : some analysis on them and produced other files in return, i would 
 : like to take not of this. i.e what i want is to recored input and 
 : outputs to a module. and also to record all paramaters, attribute 
 : vaules used by the same module.
 : 
 : I thought i would build a wrapper around the orignial python 
 : program or probably pick this information at OS level.

If I understand your description correctly....

  * you have many modules

  * you are not (so) worried about how one module calls another 
    (whether it instantiates classes from one module, in which case 
    you might find metaclasses helpful)

  * you are more worried about which module is opening what files;
    you can always learn what files are getting opened with 'strace 
    -e open', however you want to know which files are opened by 
    what module; that's application-specific

  * you are also worried about application state--you mention 
    attribute values; that's application-specific

I guess I would suggest two things:

  1. Start adding the logging code.  If the application behaviour is 
     opaque now, it's not going to get any more transparent without 
     logging.

  2. Consider learning pdb or whatever another python trace tool, 
     which may be able to provide some of the above for you.  (I 
     will be continuing to follow this thread to learn something 
     new here, as well.)

I'm really not sure what else to recommend here, JoJo.  Maybe some 
of the others on this list can help.

-Martin

-- 
Martin A. Brown
http://linux-ip.net/


More information about the Tutor mailing list