proxy.core.event.subscriber module#

⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging.

  1. 2013-present by Abhinav Singh and contributors.


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 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.

_start_relay_thread() None[source]#
_stop_relay_thread() None[source]#
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.

shutdown(do_unsubscribe: bool = True) None[source]#

Tear down subscription thread.

Call unsubscribe() to actually stop subscription.

subscribe() None[source]#
unsubscribe() None[source]#