Changeset 3665

Show
Ignore:
Timestamp:
17/11/08 00:42:38 (8 weeks ago)
Author:
tack
Message:

Fix a bug with InProgressAny?(…).wait(); add pass_index kwarg to
InProgressAny?.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/base/src/notifier/async.py

    r3658 r3665  
    469469        import main 
    470470        from thread import is_mainthread 
     471 
     472        # Connect a dummy handler to ourselves.  This is a bit kludgy, but 
     473        # solves a particular problem with InProgress(Any|All), which don't 
     474        # actually finish unless something wants to know.  Normally, without 
     475        # wait, we are yielded to the coroutine wrapper which implicitly 
     476        # connects to us.  Here, with wait(), in a sense we want to know when 
     477        # self finishes. 
     478        dummy = lambda *args, **kwargs: None 
     479        self.connect(dummy) 
     480 
    471481        if is_mainthread(): 
    472482            # We're waiting in the main thread, so we must keep the mainloop 
     
    486496 
    487497        if not self.is_finished(): 
     498            self.disconnect(dummy) 
    488499            raise TimeoutException 
    489500 
     
    565576    building state machines using coroutines. 
    566577 
    567     The InProgressAny object then finishes with a 2-tuple, whose first 
    568     element is the index (offset from 0) of the InProgress that finished, 
    569     and the second element is the result the InProgress was finished with. 
    570     """ 
    571     def __init__(self, *objects): 
     578    If pass_index is True, the InProgressAny object then finishes with a 
     579    2-tuple, whose first element is the index (offset from 0) of the InProgress 
     580    that finished, and the second element is the result the InProgress was 
     581    finished with. 
     582     
     583    If pass_index is False, the InProgressAny is finished with just the result 
     584    and not the index. 
     585    """ 
     586    def __init__(self, *objects, **kwargs): 
    572587        super(InProgressAny, self).__init__() 
     588        self._pass_index = kwargs.get('pass_index', True) 
    573589        # Generate InProgress objects for anything that was passed. 
    574590        self._objects = [ inprogress(o) for o in objects ] 
     
    630646        constructor have finished. 
    631647        """ 
    632         super(InProgressAny, self).finish((result, args)) 
     648        if self._pass_index: 
     649            data = (result, args) 
     650        else: 
     651            data = args 
     652        super(InProgressAny, self).finish(data) 
     653 
    633654        # We're done with the underlying IP objects so unref them.  In the 
    634655        # case of InProgressCallbacks connected weakly to signals (which