Re: GUI freezes waiting for callback function to return



On 13 December 2012 11:21, Mateusz Marzantowicz
<mmarzantowicz osdf com pl> wrote:
I'm writing very simple application in Python using pygobject. I'm using

What I've observed is that GUI (menu to be specific) freezes till my
callback function finishes. It's completely unacceptable for GUI

This is because callbacks are run by the main GUI thread, so until
your callback returns, the GUI can't do anything. To give a nice
experience for the user your callbacks must be very short.

If you have to do some lengthy processing, you need to process GUI
events at regular intervals. In PyGtk this used to be:

    def my_long_callback():
        for i in long_time():
            small_chunk_of_work()
            while gtk.events_pending():
                gtk.main_iteration()

I don't know what the pygobject equivalent is, something similar.

In C you can use threads for background tasks, but I think that's
difficult in Python.

John



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]