I have the following function which generates MD5 hashes for files on a
local and remote server. The remote server has a little applet that
runs from inetd and generates an MD5 hash given the file name.
The problem is that it takes 2+ minutes to generate the MD5 hash, so
this function takes about 5 minutes every time it is called. Since the
first MD5 hash is generated on a remote machine, the local machine does
nothing but wait for half that time.
Is there any way to rewrite each half of the function to run in the
background, so to speak, and then have a master process that waits on
the results? This would cut execution time in half more or less.
# checkMD5
def checkMD5(fileNa me, localDir):
# get remote hash
Socket = socket.socket(s ocket.AF_INET,s ocket.SOCK_STRE AM)
Socket.connect( (MD5server,888) )
#throw away ID string
Socket.recv(256 )
Socket.send(fil eName+'\n')
remoteMD5hash = Socket.recv(256 )
# get local hash
try:
file=open(makeM ovieName(localD ir,fileName), 'r')
except IOError:
localMD5hash = '0'
else:
hasher = md5.new()
while True:
chunk = file.read(1024)
if not chunk:
break
hasher.update(c hunk)
localMD5hash = hasher.hexdiges t()
if Debug: print "local:",localM D5hash, "remote:",remot eMD5hash
return localMD5hash.st rip() == remoteMD5hash.s trip()
-Kamus
--
o__ | If you're old, eat right and ride a decent bike.
,>/'_ | Q.
(_)\(_) | Usenet posting`
local and remote server. The remote server has a little applet that
runs from inetd and generates an MD5 hash given the file name.
The problem is that it takes 2+ minutes to generate the MD5 hash, so
this function takes about 5 minutes every time it is called. Since the
first MD5 hash is generated on a remote machine, the local machine does
nothing but wait for half that time.
Is there any way to rewrite each half of the function to run in the
background, so to speak, and then have a master process that waits on
the results? This would cut execution time in half more or less.
# checkMD5
def checkMD5(fileNa me, localDir):
# get remote hash
Socket = socket.socket(s ocket.AF_INET,s ocket.SOCK_STRE AM)
Socket.connect( (MD5server,888) )
#throw away ID string
Socket.recv(256 )
Socket.send(fil eName+'\n')
remoteMD5hash = Socket.recv(256 )
# get local hash
try:
file=open(makeM ovieName(localD ir,fileName), 'r')
except IOError:
localMD5hash = '0'
else:
hasher = md5.new()
while True:
chunk = file.read(1024)
if not chunk:
break
hasher.update(c hunk)
localMD5hash = hasher.hexdiges t()
if Debug: print "local:",localM D5hash, "remote:",remot eMD5hash
return localMD5hash.st rip() == remoteMD5hash.s trip()
-Kamus
--
o__ | If you're old, eat right and ride a decent bike.
,>/'_ | Q.
(_)\(_) | Usenet posting`
Comment