Reputation: 9538
Is there a way to not block PyGTK while performing some expensive operation? I know threading would work but it would take a lot of code and setup.
Thanks,
Upvotes: 1
Views: 763
Reputation: 26524
Avoid threads, they don't work well at all with PyGTK. Some alternatives:
Twisted is a great library for doing networking, which is completely non-blocking and integrates well with the PyGTK mainloop, consider using that.
Upvotes: 0
Reputation: 1331
Threading is not really a good choice in pygtk. Just check the main loop for events in your expensive loop by doing, and let it do its thing:
while my_operation_running:
<my code>
while gtk.events_pending():
gtk.main_iteration()
or tweak your expensive operation so it can be run step-by-step using
glib.idle_add(function)
Every time main loop doesn't have something to do, it will call "function", just make sure function keeps track of its progress and it makes only one iteration in each call.
Upvotes: 1