I have a Logger class with the following:
class Logger():
def __init__(self):
self.terminal = sys.__stdout___
self.log = open('logFile.log', 'w')
def write(message):
self.terminal.write(message)
self.log.write(message)
a main with the following:
import Logger, sys
sys.stdout = Logger.Logger()
import File1
File1.aFunc()
in File1:
def execSubProc(target,queue):
target(queue)
q = multiprocess.Queue()
proc = multiprocess.Process(target=execSubProc, args=(testFunc,q))
proc.start()
proc.join()
in File2:
def testFunc(queue)
#Some print statements
#I want to get these print statements in the queue for main process to read
Okay, so here is my structure. What I am trying to do is get the stdout from the child process running testFunc() and put it into the queue. When the program returns to main, i want to read from the queue and write those contents to the log file.
I can't just do sys.stdout = Logger.Logger() in file 2 again, because that will just overwrite mains log file. What can I do to capture all of child processes stdout and put in queue?