Package zeroinstall :: Package support :: Module tasks :: Class Blocker
[frames] | no frames]

Class Blocker

source code

A Blocker object starts life with 'happened = False'. Tasks can ask to be suspended until 'happened = True'. The value is changed by a call to trigger().

Example:

>>> kettle_boiled = tasks.Blocker()
>>> def make_tea():
        print "Get cup"
        print "Add tea leaves"
        yield kettle_boiled
        print "Pour water into cup"
        print "Brew..."
        yield tasks.TimeoutBlocker(120)
        print "Add milk"
        print "Ready!"
>>> tasks.Task(make_tea())

Then elsewhere, later:

       print "Kettle boiled!"
       kettle_boiled.trigger()

You can also yield a list of Blockers. Your function will resume after any one of them is triggered. Use blocker.happened to find out which one(s). Yielding a Blocker that has already happened is the same as yielding None (gives any other Tasks a chance to run, and then continues).

Instance Methods
 
__init__(self, name) source code
 
trigger(self, exception=None)
The event has happened.
source code
 
__del__(self) source code
 
add_task(self, task)
Called by the schedular when a Task yields this Blocker.
source code
 
remove_task(self, task)
Called by the schedular when a Task that was waiting for this blocker is resumed.
source code
 
__repr__(self) source code
 
__str__(self) source code
Class Variables
  exception = None
Create a new digest.
Method Details

trigger(self, exception=None)

source code 

The event has happened. Note that this cannot be undone; instead, create a new Blocker to handle the next occurance of the event.

Parameters:
  • exception ((Exception, traceback)) - exception to raise in waiting tasks

add_task(self, task)

source code 

Called by the schedular when a Task yields this Blocker. If you override this method, be sure to still call this method with Blocker.add_task(self)!