I have couple of processes with its own threads all writing to
fd = os.open("foo.txt", os.O_RDWR|os.O_CREAT )
fd2 = 2
# rest of the code
if __name__ == '__main__':
raise Exception("My Exception")
Use dup2 to redirect the output to a file of your choice. Set fd to your file descriptor and fd2 to 1 (stdout).
Note: Do this inside the spawned thread, not in the main thread.