One possible way to avoid reentrancy could be to use idle handlers. 
Example:

def my_callback(args):
        obj, arg1, arg, ... = args
        # ....
        return False

# ...
some_object.connect("signal-name", lambda obj, arg1, arg2, ...: 
gobject.idle_add(my_callback, (obj, arg1, arg, ...))

  Given how much run-time oriented python is, it should be fairly easy
to make a generic proxy function or class that takes care of this
easily, like this:

class IdleHandlerProxy(object):
        def __init__(self, callback):
                self.__cb = callback
        def __call__(self, *args):
                gobject.idle_add(self.__proxy_func, args)
        def __proxy_func(self, *args):
                self.__cb(*args)
                return False

then:
        some_object.connect("signal-name", IdleHandlerProxy(my_callback), data)

  Warning: code is untested.

A Qui, 2004-01-15 �s 22:58, Tim Newsham escreveu:
> Hi,
>    I recently tracked down a bug in my gtk/python app.  The cause is
> that one of the GTK signal handlers I have is being invoked in
> a reentrant manner.  I'm unsure what the best/proper way to deal
> with this is.
> 
> Here's a quick description of what's going on.  I have a handler
> for button click events.  When a button click is received, I
> construct a GtkMenu and pop it up for the user to select something.
> The menu has items in it that connect to callback functions when
> selected.  Now what is happening is that if the user clicks several
> times rapidly, the menu items show up and the user can rapidly
> select two menu items.  When the function for handling this selection
> is invoked, it must do something internally which allows gtk to
> process some more signals, because the same handler is then invoked
> again before it is finished handling the first selection.
> 
> My question is.. what is the "right" way, or at least a good way
> of handling this in GTK and PyGTK in particular?  Since I am
> using context menus in a number of places in a similar fashion
> I fear there may be other race conditions like this in my code.
> I would like to have a good mechanism for serializing the use
> of the context menu.  I think one solution would be if all other
> gtk interactions were disabled while a context menu was active
> (if this isnt already the case).  Would that work or would I just
> be making the race smaller?
> 
> Tim N.
> 
> _______________________________________________
> pygtk mailing list   [EMAIL PROTECTED]
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
-- 
Gustavo J. A. M. Carneiro
<[EMAIL PROTECTED]> <[EMAIL PROTECTED]>

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to