I am creating a project in Python and I would like to add a monitoring system that makes use of events and event handlers. I would like this system to be available throughout the project. I have the following operations in mind:
- Defining an event. The event can take some data as parameters.
- Defining a monitor. A monitor registers for a certain event. Multiple monitors can register for the same event. I want to create different kinds of monitors, e.g. one to print data, one to create plots with the data, etc. Thus a monitor should be a class, capable of holding all the data it collects until some method (e.g. print, create-log, ...) is called.
- Defining an event-handler for a monitor-event pair. This defines how the given monitor will respond to the given event. This action will mostly be: add this data to the data-list of the instance of some monitor class.
- A notify function that can notify when an event has occurred. This will trigger the event-handler for all monitors that are registered for that event. Ideally, the notify function should be callable from anywhere in the project.
How can I create such a system? Are there any libraries that can help me with this? I am especially wondering how I can make this system in such a way that it is transparently available throughout the project.