Using win32api.GetTickCount() over the network
Dave Brueck
dave at pythonapocrypha.com
Wed Mar 5 15:37:42 EST 2003
On Wed, 5 Mar 2003, Donovan Hide wrote:
> is there a way to connect to a remote machine and use
> win32api.GetTickCount() call to measure how long a machine has been up, in a
> smilar way to the MS utility uptime.exe. Also does anyone know how to
> control services and processes on remote machines without using other .exe
> utilities such as those from sysinternals.
> I am writing a wxPython utility to monitor and control a 3d renderfarm
> and your assistance would be gratefully received.
Hi Donovan,
Probably the easiest and most flexible thing to do is run a custom Python
"listener" on each machine in the render farm. Here's some untested code
to illustrate:
On the listener size:
CMD_GET_TICKS = 1
import SocketServer, pickle
class Handler(SocketServe.BaseRequestHandler):
def handle(self):
cmd = self.request.recv(1)
if cmd == CMD_GET_TICKS:
self.request.send(cPickle.dumps(win32api.GetTickCount()))
else:
self.request.send('Huh?')
addr = ('10.20.30.5', 5000) # Listen on this address
server = SocketServer.ThreadingTCPServer(addr, Handler)
server.serve_forever()
On the server side (your wxPython monitoring app):
import socket, cPickle
def GetTickCount(addr):
s = socket(AF_INET, SOCK_STREAM)
s.connect(addrd)
s.send(CMD_GET_TICKS)
data = ''
while 1:
more = s.recv(1024)
if not more: break
data += more
return cPickle.loads(data)
You can of course get much fancier by adding additional commands (kill the
render process, restart the render process, check free disk space, check
number of frames done, etc.) as well as adding the ability to send
parameters as part of the commands to the render nodes.
-Dave
More information about the Python-list
mailing list