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

Class Blocker

source code

object --+
         |
        Blocker

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, "Brewing")
        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)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
trigger(self, exception=None)
The event has happened.
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)
repr(x)
source code
 
__str__(self)
str(x)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Class Variables
  exception = None
Create a new digest.
Properties

Inherited from object: __class__

Method Details

__init__(self, name)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  • name (str)
Overrides: object.__init__

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)!

Parameters:

remove_task(self, task)

source code 

Called by the schedular when a Task that was waiting for this blocker is resumed.

Parameters:

__repr__(self)
(Representation operator)

source code 

repr(x)

Overrides: object.__repr__
(inherited documentation)

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)