Communication between remote scripts

Tim Golden tim.golden at viacom-outdoor.co.uk
Wed Sep 15 09:15:06 EDT 2004


| > In fact, given a certain interpretation of the description (remote 
| > monitoring of a running process) it might well be possible to do
| > the whole thing in WMI. I have certainly had scripts running on my
| > machine to monitor the progress of processes on several of 
| the servers 
| > here. Depends what's needed exactly
| 
| Fantastic! I think, in this case, that would do the trick.
| 
| I have the following code that will monitor a process on a local 
| machine. 
| 
| Can you give me an example of how to monitor a process on a remote 
| computer?
|
| <code>
| while (appRun == "1"):
|         #print "Waiting %d seconds for app to close" % i
|         rc = win32event.WaitForMultipleObjects(
|                               handles, # Objects to wait for.
|                               1, # Wait for them all
|                               1000) # timeout in milli-seconds.
|         if rc == win32event.WAIT_OBJECT_0:
|             # Our processes closed!
|             print "Process stopped."
|             appRun = "0"
|         else:
|             print "running"
|             time.sleep(5)
| </code>

Hmmm... If I understand what you're doing here, you're using
some Win32 Objects as semaphores and then waiting for them
all to fire to indicate that they've finished. I presume this
involves explicitly creating suitable semaphores and waiting
for them to fire? To the best of my knowledge, the simple
objects can't cross machine boundaries. Named pipes and mailslots
can, which may be a possible way to go, but I haven't tried
that.

Assuming that by "monitor a process" you mean "detect when 
a process has completed" then this is an example of the sort of 
thing you want:
http://tgolden.sc.sabren.com/python/wmi_cookbook.html#watch_notepad

Substitute the name of a remote machine into the WMI constructor
to watch for a process on another machine. Watching several machines
at once is a bit more tricky, but not much. There's an example of
using multiple watchers in the docstring for wmi.WMI.watch_for.

If you want to go down this road and can't see what I'm on
about, let me know and I'll dig up a more complete example.

TJG

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________



More information about the Python-list mailing list