whistle.listeners¶
- class ListenersCollection[source]¶
Bases:
object- add(event_id, listener, /, *, priority=0)[source]¶
Add a listener for the given event id, with the given priority.
Priority must be a number between -127 and 128, inclusive. As a convention coming from unix process priorities, we use priorities ranging from -20 (highest priority) to 20 (lowest priority), with 0 being the default priority.
The actual permited range is so because python dicts are WAY faster with string keys than integers. This fact still puzzles me but the difference is huge. The same rationale applies to the event_id parameter: although we could support arbitrary hashable values as event ids (and we encouraged so in whistle 1.x), we now restrict it to strings for performance reasons.