proxy.core.event.subscriber module#
proxy.py#
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging.
- copyright
2013-present by Abhinav Singh and contributors.
- license
BSD, see LICENSE for more details.
- class proxy.core.event.subscriber.EventSubscriber(event_queue: proxy.core.event.queue.EventQueue, callback: Callable[[Dict[str, Any]], None])[source]#
Bases:
object
Core event subscriber.
Usage: Initialize one instance per CPU core for optimum performance.
EventSubscriber can run within various context. E.g. main thread, another thread or a different process. EventSubscriber context can be different from publishers. Publishers can even be processes outside of the proxy.py core.
multiprocessing.Pipe
is used to initialize a new Queue for receiving subscribed events from eventing core. Note that, core EventDispatcher might be running in a separate process and hence subscription queue must be multiprocess safe.When
subscribe
method is called, EventManager stars a relay thread which consumes event out of the subscription queue and invoke callback.NOTE: Callback is executed in the context of relay thread.
- static relay(sub_id: str, shutdown: threading.Event, channel: multiprocessing.connection.Connection, callback: Callable[[Dict[str, Any]], None]) None [source]#
- setup(do_subscribe: bool = True) None [source]#
Setup subscription thread.
Call subscribe() to actually start subscription.