I am trying to redirect the stdout following the example in http://www.blog.pythonlibrary.org/2009/01/01/wxpython-redirecting-stdout-stderr/. My code has some loops, and I would like the function to redirect stdout each time the loop is repeated, as it happens when running the code with the command line. However, it seems that in this example the stdout is only redirected when the whole function is finished. How can I redirect the stdout in a "real time" mode? I attach my code.