Created
May 29, 2014 16:38
-
-
Save namoopsoo/104dd7c568df17255bb5 to your computer and use it in GitHub Desktop.
Here is a straightforward way to capture the standard and error outputs from a custom process you are running. Back-linking to http://stackoverflow.com/a/23937468/472876
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Process | |
import os | |
import sys | |
class MyProc(Process): | |
def run(self): | |
# Define the logging in run(), MyProc's entry function when it is .start()-ed | |
# p = MyProc() | |
# p.start() | |
self.initialize_logging() | |
print 'Now output is captured.' | |
# Now do stuff... | |
def initialize_logging(self): | |
sys.stdout = open(str(os.getpid()) + ".out", "a", buffering=0) | |
sys.stderr = open(str(os.getpid()) + "_error.out", "a", buffering=0) | |
print 'stdout initialized' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment