gobject main loop and sys.stdin.readline
Hello,
I'm writing an audio player console application.
This is not purely GTK, but it uses gobject.
It requires:
1) running gobject.MainLoop in order to be notified of gstreamer events
2) catching user input from keyboard
I try to read user input in a thread, but it does not work.
Code:
1 2 3 4
| self.main_loop = gobject.MainLoop()
self.thread = threading.Thread(None, self._thread, 'commands thread')
self.thread.start()
self.main_loop.run() |
Then, in my thread:
Code:
1 2 3
| def _thread(self):
cmd = sys.stdin.readline().strip()
print cmd |
User input is not read in the thread until I stop main loop (control-c).
How can I run main loop and listen to user input at the same time?