Status of processes running inside an object
thomas at xs4all.net
Thu Feb 3 09:26:34 EST 2000
On Thu, Feb 03, 2000 at 02:54:07PM +0100, Thomas Weholt wrote:
> What`s the best method, if do-able, to get info about a process running
> inside a object?
> Here`s an example :
> I got a cd-object that scans thru a cd and does alot of stuff with the
> things it discovers. How could I track the progress of the scanning
> procedure without making alot of print "Scanning files ...", print
> "Indexing documents ...." etc. in the object-code?
> Is there a way of tracking the state of processes inside an object
> without printing stuff inside the object itself or stopping in the
> process so that code outside the object can check the contents of the
> This is probably impossible, crazy or <insert_word>, but I`d like some
I'm not really clear on what kind of information you want from the object.
For a sensible answer, more information would be nice ;) I can tell you,
though, that if you want simple status information, like 'scanning files',
'indexing...', 'writing result', etc. the easiest way is by doing the
'print's you so dislike. Or rather, avoid print and use seperate logfile
instead, or store status info in module/class/instance level attributes.
Alternatively, if you want very finegrained control over your application,
but you dont want to add logfile-notifications on every other line, try
using sys.settrace() or sys.setprofile(). They're documented in the debugger
and profiler chapters, respectively, of the library reference. settrace()
registers a function that gets called whenever your process makes a function
call. setprofile() registers a function that gets called whenever your
process makes a function call and on every return. (And the functions get
passed relative info about the function calls in question, of course.)
Or perhaps your demands go as far as interaction with the running process;
you should probably look at 'asyncore', and set up your program as a tcp/ip
or unix-socket server, allowing clients to connect, retrieve information
about the status of the process and execute commands to influence it.
Or if you're very fond of threading, or interested in threading, you can do
even more ;) You can use threading and a simple telnetserver, not asyncore,
to do roughly the same as you would using asyncore above, or, if you really
only need one 'client' to connect, you can use threading to make one process
be both the worker and the user interface.
Any of these solutions could be The Best Way, or none of them could be the
right way -- it all depends on exactly what you want to do ;)
Thomas Wouters <thomas at xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
More information about the Python-list