0

I'm trying to create a simple Python application for Linux and I'm using GTK to generate a UI for it. I've only begun exploring GTK but from what I can tell, the moment you call GTK.main() the program goes into that function wherever and only responds to user interactions with the UI. The thing is, I'm running an SDN controller (POX) alongside, and I want the events associated with instances of POX objects to also be able to run (which currently isn't happening since the program gets stuck in 'GTK.main()' forever).

I've considered creating a new thread and calling GTK.main() from there, but then I'll have to worry about thread safety. Isn't there some way where the events for both the UI as well as the objects instantiated in the rest of the program fire alongside?

Ali250
  • 652
  • 1
  • 5
  • 19
  • I *think* you want to keep the GTK process in the main thread. Generally while entering a run loop to handle user actions this is the desired behavior. It sounds like the other controller should notify an object that is being observed in your main() run loop with any actionable changes. – errata May 16 '15 at 21:30
  • So I spawned another thread for the controller and called `GTK.main()` through the main thread and it still seems to be messing up. Somehow the call to GTK.main() is also jamming the other thread, because as soon as I close the UI window the other thread continues running. This is all pretty new to me. I'm used to .NET programming where spawning a new thread is substantially easier :/ – Ali250 May 17 '15 at 11:36
  • Wait, are you calling `GTK.main()` from both threads? – andlabs May 17 '15 at 14:03
  • @Ali250 if you are calling `GTK.main()` on both threads, that's your issue. You should only call `GTK.main()` from one thread. When you create a new thread, you can go ahead and start doing work on it. If you need to update the UI, you can do so with with idle callbacks; not sure how they work in Python. – andlabs May 19 '15 at 17:21
  • I wasn't calling GTK.main() from both threads, just one. Anyway I managed to resolve it by spawning two threads, one for GTK and the other for my POX controller. – Ali250 May 20 '15 at 08:18
  • The I suggest you edit you original question, and add a note how the problem was solved. Or answer your own question. – jcoppens May 20 '15 at 20:16

1 Answers1

0

I was able to solve the problem by spawning separate threads for both GTK and the POX controller. With this done, everything's working fine simultaneously.

Ali250
  • 652
  • 1
  • 5
  • 19