Handler definitions


In [1]:
def printer(*args, **kwargs):
    print args, kwargs

def pretty_printer(*args, **kwargs):
    import pprint
    pprint.pprint(args)
    pprint.pprint(kwargs)
    
def errorer(*args, **kwargs):
    raise Exception

Event


In [2]:
from notify.signal import Signal

do = Signal()

Are multiple handlers allowed


In [3]:
do.connect(printer)
do.connect(pretty_printer)

In [4]:
do(1, 2, a=3)


(1, 2) {'a': 3}
(1, 2)
{'a': 3}

Are duplicate handlers detected?


In [6]:
do.connect(printer)
do(1, 2, a=3)


(1, 2) {'a': 3}
(1, 2)
{'a': 3}
(1, 2) {'a': 3}

Do errors stop all handlers


In [7]:
do2 = Signal()

do2.connect(errorer)
do2.connect(printer)
do2(1, 2, a=3)


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
/Users/sc015622/VirtualEnvs/observers/lib/python2.7/site-packages/notify/signal.pyc in emit(self, *arguments, **keywords)
   1168                     if accumulator is None:
   1169                         try:
-> 1170                             handler (*arguments, **keywords)
   1171                         except:
   1172                             AbstractSignal.exception_handler (self, sys.exc_info () [1], handler)

<ipython-input-1-1bd812cf050d> in errorer(*args, **kwargs)
      8 
      9 def errorer(*args, **kwargs):
---> 10     raise Exception

Exception: 
(1, 2) {'a': 3}

Project health

Overall: very low


In [ ]: