Hello. Thank you for your code. To be honest I didn't understand it well. So I will try to explain my situation. I have a code (written in python) in this one i call an other one and everything ok. i receive the results that I was looking for. BUT when I am calling an other code, doesnt work. which is the right way to call this:
import os, sys, traceback, hashlib, stat, mmap, multiprocessing, re, os.path, subprocess, commands, pipes
from multiprocessing import Process, JoinableQueue
from os import listdir
from os.path import isfile, join
from os import walk
from string import Template
inst_name = "in14"
copy ="/users/in14"
original ="/users/experiment_in14"
num_procs = multiprocessing.cpu_count()
num_procs *= 4
files = []
subdirs = []
#import statistic14
def main ():
pass
def get_hash(fh, sz):
h = hashlib.sha1()
while True:
buf = fh.read(65536)
if len(buf) == 0: break
h.update(buf)
return h.digest()
def chk(path, lf, copy):
path = os.path.join(copy, path)
path1 = os.path.join(original, path)
st = None
st1 = None
try:
st = os.lstat(path)
st1= os.lstat(path1)
except:
lf.write("Missing from the original: " + path + "\n")
lf.flush()
return
if not stat.S_ISREG(st.st_mode):
return
if st.st_size != st1.st_size:
lf.write("c.Size differ: " + path + "\n")
lf.flush()
return
if st.st_size == 0: return
hv = None
hv1 = None
try:
fh = open(path, "r")
hv = get_hash(fh, st.st_size)
fh.close()
fh = open(path, "r")
hv1 = get_hash(fh, st.st_size)
fh.close()
except:
lf.write("c.Open error: " + path + "\n")
lf.flush()
return
if hv != hv1:
lf.write("c.Digests differ: " + path + "\n")
lf.flush()
def proc_chk(q, lf,copy):
while True:
path = q.get()
if path == "done":
break
chk(path, lf, copy)
q.task_done()
q.task_done()
basedir=os.getcwd()
q = JoinableQueue()
lf = open("/users/compare14", "w")
path = os.path.realpath(sys.argv[0])
path1 = os.path.realpath(sys.argv[0])
o_cwd = os.getcwd()
os.chdir(copy)
cwd = os.getcwd()
for i in range(0, num_procs):
p = Process(target=proc_chk, args=(q, lf, original))
p.start()
for dirpath, dirnames, filenames in os.walk(".", followlinks=False):
for f in filenames:
q.put(os.path.join(dirpath, f))
for i in range(0, num_procs):
q.put("done")
q.join()
lf.close()
os.chdir(o_cwd)
##################################################################################################
def get_hash(fh, sz):
h = hashlib.sha1()
while True:
buf = fh.read(65536)
if len(buf) == 0: break
h.update(buf)
return h.digest()
def chk(path, lf, original):
path1 = os.path.join(original, path)
st = None
st1 = None
try:
st = os.lstat(path)
st1 = os.lstat(path1)
except:
lf.write("Missing from the copy: " + path1 + "\n")
lf.flush()
return
if not stat.S_ISREG(st.st_mode):
return
if st.st_size != st1.st_size:
lf.write("c.Size differ: " + path + "\n")
lf.flush()
return
if st.st_size == 0: return
hv = None
hv1 = None
try:
fh = open(path, "r")
hv = get_hash(fh, st.st_size)
fh.close()
fh = open(path1, "r")
hv1 = get_hash(fh, st.st_size)
fh.close()
except:
lf.write("Open error: " + path + "\n")
lf.flush()
return
if hv != hv1:
lf.write("c.Digests differ: " + path + "\n")
lf.flush()
def proc_chk(q, lf, original):
while True:
path1 = q.get()
if path1 == "done":
break
chk(path1, lf, original)
q.task_done()
q.task_done()
q = JoinableQueue()
lf = open("/users/compare14", "a+")
path = os.path.realpath(sys.argv[0])
path1 = os.path.realpath(sys.argv[0])
o_cwd = os.getcwd()
os.chdir(original)
cwd = os.getcwd()
for i in range(0, num_procs):
p = Process(target=proc_chk, args=(q, lf, copy))
p.start()
for dirpath, dirnames, filenames in os.walk(".", followlinks=False):
for f in filenames:
q.put(os.path.join(dirpath, f))
for i in range(0, num_procs):
q.put("done")
q.join()
lf.close()
os.chdir(o_cwd)
if __name__ == '__main__':
main()