|
Apologies in advance, I don't have a lot of experience in multithreaded programming nor in gtk, and I'm working on this project that involves both.
I have a Python program that's currently used to crunch a bunch of numbers. I want to add a gtk interface to it to display results as they're computed, and to allow parameters to be changed while it's running... I'd also like the thread to be agnostic to the toolkit I use, so I don't want any gtk code in there.
I've moved all my calculations to a separate Python thread. The question is how to properly pass data to and from that thread. Probably a queue, sure, but more specifically, I'm not sure how to handle checking it. That is, the gtk interface is executing its own main loop. Somewhere in there, I need to regularly check some queue to see if there's a message from the thread. What's the way to do that without interfering with the main loop?
Since I don't know how to write any of this, I can't provide any sample code, but here's a simple two-part program that would exemplify what I want to do. I'd like a gtk window with a button and a number box. When the button gets pressed, I'd like the thread to sleep for a second, then randomly choose a number and put it in the number box. So basically, I want two-way communication without the thread knowing anything about gtk.
What's the right way to write code like this? Thanks!
|