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]:
import nmevent
do = nmevent.Event()

Are multiple handlers allowed?


In [3]:
do += printer
do += pretty_printer

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


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

Are duplicate registrations detected?


In [5]:
do += printer
do(1, 2, a=3)


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

Do errors stop all handlers?


In [6]:
do2 = nmevent.Event()

do2 += errorer
do2 += printer
do2(1, 2, a=3)


(1, 2) {'a': 3}
---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-6-729987fa26d7> in <module>()
      3 do2 += errorer
      4 do2 += printer
----> 5 do2(1, 2, a=3)

/Users/sc015622/VirtualEnvs/observers/lib/python2.7/site-packages/nmevent.pyc in fire(self, sender, *args, **keywords)
    372         """Fires this event and calls all of its handlers.
    373         """
--> 374         self.handlers.call(sender, *args, **keywords)
    375     __call__ = fire
    376 

/Users/sc015622/VirtualEnvs/observers/lib/python2.7/site-packages/nmevent.pyc in call(self, *args, **keywords)
    265         """Calls all callbacks with the given arguments."""
    266         for callback in self.callbacks:
--> 267             callback(*args, **keywords)
    268 
    269 class WeakRefCallbackStore(CallbackStore):

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

Exception: 

Project health

  • Source code: https://github.com/nnen/nmevent
  • Releases: 0
  • Commit activity: No activity in a year (back to Aug 2013), couple of commits the year prior, then nothing until back in '10

Overall: very low


In [ ]: