I asked a question yesterday about a problem with a program I'm writing in Python ( Passing wxPython objects as multiprocessor arguments ). I managed to solve that problem by using a multiprocess process for the function that evaluates the scripts. However, since the scripts are runned from a different process, their output is not properly redirected to my wxPython TextCtrl window. So, I'm looking for way to continously redirect the output from the childprocess to my main process so it can be written to my text window.
This is the function that sets up the process:
def createprocess(test): q = Queue() q.put(test) p = Process(target=runtest, args=(q,)) p.start() p.join() return q.get() This is the target function of the process:
def runtest(q): test = q.get() exec 'import ' + test func=test+'.'+test+'()' ret = eval(func) q.put(ret) I found this thread ( How can I send python multiprocessing Process output to a Tkinter gui ) which describes how to redirect output from the childprocess but the problem was that the output was received after the evaluation was complete.
eval". This entire method is wrong and redirecting output is not going to fix it.testmodule = __import__(test), thenret = getattr(testmodule, test)()? That would at least be better thaneval. Also, why is yourtestprinting the output instead of usingyieldorreturn? This is wrong in any language to output info from a function.