Use subprocesses in simple way...

DurumDara durumdara at gmail.com
Thu May 11 04:22:43 EDT 2006


10 May 2006 04:57:17 -0700, Serge Orlov <Serge.Orlov at gmail.com>:
> I thought md5 algorithm is pretty light, so you'll be I/O-bound, then
> why bother with multi-processor algorithm?

This is an assessor utility.
The program's architecture must be flexible, because I don't know,
where it need to run (only I have a possibility to fix this: I write
to user's guide).

But I want to speedup my alg. with native code, and multiprocess code.
I not tested yed, but I think that 4 subprocess quickly as one large 
process.

>
> > 2.)
> > Do you know command line to just like FSUM that can compute file
> > hashes (MD5/SHA1), and don't have any problems with unicode alt. file
> > names ?
>
> I believe you can wrap the broken program with a simple python wrapper.
> Use win32api.GetShortPathName to convert non-ascii file names to DOS
> filenames.

I use FindFilesW with 8. (?) parameter. This is the alternative name
of the file, but yet I found a file that not handled by FSUM
utility...

Thanx for help:
dd

Ps:
I wrote some code to test pipes and subprocesses. The name of the mod.
is testpipe.py.
The code is:

import sys,random,subprocess,time,os,popen2,threading,thread

IsMaster=len(sys.argv)==1

class ProcessThread(threading.Thread):
    def __init__(self,Param):
        threading.Thread.__init__(self)
        self.Param=Param
        self.RetVal=None
        self.start()

    def run(self):
        param=self.Param
        print "New thread with param",param
        po=os.popen2('c:\\python24\\python.exe testpipe.py 1')
        child_stdin,child_stdout=po
        child_stdin.write(str(param)+'\n')
        retval=child_stdout.readlines()
        child_stdin.close()
        child_stdout.close()
        self.RetVal=retval

if IsMaster:
    print "M:",time.time()
    print "M: Start"
    print "M: Open subprocess"
    cnt=1
    fcnt=0
    pths=[]
    ress=[None]*9
    while True:
        if cnt<10:
            pt=ProcessThread(cnt)
            pths.append(pt)
            cnt+=1
        pcnt=0
        for pt in pths:
            if pt: pcnt+=1
        if pcnt:
            for i in range(len(pths)):
                pt=pths[i]
                if pt and pt.RetVal:
                    pths[i]=None
                    ress[i]=pt.RetVal
                    print [pt.RetVal]

        else:
            break
    print "\M: The results are:"
    for s in ress:
        print s
    print "M: End"
else:
    print "S:",time.time()
    print "S: Start"
    print "S: Data"
    print "S: End"
    s=sys.stdin.readline()
    print "S: %s"%s
    time.sleep(1)
    print "Echo: %s"%s
    print "Finished"




More information about the Python-list mailing list