I've got a wx-gui that's piping stdout/stderr to two different text-controls. In the program I'm creating a process to run some data-crunching code, and I have a thread that joins the process and changes the global state when the process is finished.
import multiprocessing as mp
from threading import Thread
t = Thread(target=self.join_proc)
self.process = mp.Process(target=self.currentProc.Run, args=(0,))
self.process.start()
t.start()
def join_proc(self):
self.process.join()
self.state.transition(SIMULATION_ACTIVE)
The problem is that the first time stdout is used after the join, the program crashes in one of several variants where GTK complains/aborts/segfaults due to various errors that happen in the textctrls, for example:
(python:15592): Gtk-WARNING **: Invalid text buffer iterator: either the iterator is
uninitialized, or the characters/pixbufs/widgets in the buffer have been modified
since the iterator was created.
This smells like a threading issue, but I can't figure out how to work around the problem. I've tried setting stdout/stderr back to the default sys.__std[err|out]__
while the process/thread exist but that doesn't help. Currently I have a wrapper around the textctrls that takes care of the forking calling flush() on the stdout/stderr, that does nothing. This function feels like it may hold a solution, i.e. flush before/after doing something smart with the textctrl's.
How can I use the textctrl objects to get this working? Alternatively, what's a better option for doing the process/callback bit than my current process/thread-joiner set up?