Good day!
I have a python script, it creates a file list and processes it in multiprocess.Pool.map and thread function. Thread function uses outside executable and calls it via subprocess.check_call. This outter executable prints some information to stdout.
So I have problem with reading this output - sometimes it's messed and I can't get any useful information from it. I've read about printing and multithreading in python but I think it's not exactly my problem, because I don't explicitly call print function in my script.
How can I solve this problem? Thank you.
Also, I have noticed that if I redirect output from my script to a file, the output isn't messed at all.
[UPDATE]:
This works fine if I run script: python mp.py > mp.log
import time, argparse, threading, sys
from os import getenv
from multiprocessing import Pool
def f(x):
cube = x*x*x
print '|Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut %d|'%(cube)
return cube
if __name__ == '__main__':
#file = open('log.txt', 'w+')
parser = argparse.ArgumentParser(description='cube', usage='%(prog)s [options] -n')
parser.add_argument('-n', action='store', help='number', dest='n', default='10000', metavar = '')
args = parser.parse_args()
pool = Pool()
start = time.time()
result = pool.map(f, range(int(args.n)))
end = time.time()
print (end - start)
#file.close()