timeout on os.popen3?
selwyn
selwyn at home.net.nz
Sun Jul 13 07:41:51 EDT 2003
hi all,
I would like some advice on how I can include a timeout for a scanning
operation using unzip on linux and os.popen3.
I am scanning through about 30g of rescued zip files, looking for xml
extensions within those files. What I have put together 'works', but
only for what appears to be properly reconstructed files.
Unfortunately, some aren't AND for some reason no standard error
messages are being triggered. This causes my script to hang indefinitely.
What I would like is for the script to move on to the next file, after
say a 10sec period of inactivity, but am unsure how this could be
included. I have googled around and think the select module may be
helpful, but after reading the docs I am still confused :-(
Here is what I have so far:
#!/usr/bin/python
import os,sys, time, string
filesscanned=0
possibles=0
nonzips=0
files=[]
a = os.listdir(sys.argv[1])
for i in a:
print i
stdin, stdout, stderr = os.popen3('unzip -l %s%s' % (sys.argv[1], i))
if stderr.read()=='':
zippedfiles = string.lower(stdout.read())
if zippedfiles.find('xml')!= -1:
os.system("""cp '%s%s' candidates"""% (sys.argv[1], i))
possibles +=1
print 'found a candidate:- %s%s'% (sys.argv[1],i)
files.append(i)
else:
os.system("""cp '%s%s' nonzips"""% (sys.argv[1], i))
nonzips +=1
print 'found nonzip or broken file:- %s' %i
filesscanned +=1
Any help gratefully received.
cheers,
Selwyn.
More information about the Python-list
mailing list