I have a dual-threaded application: GUI and some background work. I am trying to send requests to the main thread to do GUI updates (move the progress bar), but it does not seem to work. I dropped it to a really minimal example:
import pygtk
pygtk.require('2.0')
import glib
import gtk
import threading
import sys
import time
def idle():
sys.stderr.write('Hello from another world.\n')
sys.stderr.flush()
gtk.main_quit()
def another_thread():
time.sleep(1)
glib.idle_add(idle)
thread = threading.Thread(target=another_thread)
thread.start()
gtk.main()
It should, I thought, print something standard error from the main / GUI stream, but nothing happens. And he also does not leave, therefore gtk.main_quithe is not called.
Also, adding more output to the stderracts weird. If I changed the stream function to:
sys.stderr.write('----\n')
sys.stderr.write('----\n')
sys.stderr.flush()
sys.stderr.write('After.\n')
sys.stderr.flush()
I see 1, sometimes 2 lines of output. It looks like some kind of race condition when the main stream is introduced gtk.main, but I don't know why it would be.