Skip to content
Back to top

# `gevent.events` – Publish/subscribe event infrastructure

Publish/subscribe event infrastructure.

When certain “interesting” things happen during the lifetime of the process, gevent will “publish” an event (an object). That event is delivered to interested “subscribers” (functions that take one parameter, the event object).

Higher level frameworks may take this foundation and build richer models on it.

`zope.event` will be used to provide the functionality of `notify` and `subscribers`. See `zope.event.classhandler` for a simple class-based approach to subscribing to a filtered list of events, and see zope.component for a much higher-level, flexible system. If you are using one of these systems, you generally will not want to directly modify `subscribers`.

Added in version 1.3b1.

Changed in version 23.7.0: Now uses `importlib.metadata` instead of `pkg_resources` to locate entry points.

exception DoNotPatch

  Bases: `BaseException`

  Subscribers to will-patch events can raise instances of this class to tell gevent not to patch that particular item.

class EventLoopBlocked(greenlet, blocking_time, info, *, hub=None)

  Bases: `object`

  The event emitted when the event loop is blocked.

  Implements `IEventLoopBlocked`.

class GeventDidPatchAllEvent(patch_all_arguments, patch_all_kwargs)

  Bases: `_PatchAllMixin`, `GeventDidPatchEvent`

  Implementation of `IGeventDidPatchAllEvent`.

  ENTRY_POINT_NAME = 'gevent.plugins.monkey.did_patch_all'

    The name of the setuptools entry point that is called when this event is emitted.

class GeventDidPatchBuiltinModulesEvent(patch_all_arguments, patch_all_kwargs)

  Bases: `_PatchAllMixin`, `GeventDidPatchEvent`

  Implementation of `IGeventDidPatchBuiltinModulesEvent`.

  ENTRY_POINT_NAME = 'gevent.plugins.monkey.did_patch_builtins'

    The name of the setuptools entry point that is called when this event is emitted.

class GeventDidPatchModuleEvent(module_name, source, target)

  Bases: `GeventDidPatchEvent`

  Implementation of `IGeventDidPatchModuleEvent`.

  ENTRY_POINT_NAME = 'gevent.plugins.monkey.did_patch_module'

    The name of the setuptools entry point that is called when this event is emitted.

class GeventPatchEvent(source, target)

  Bases: `object`

  Implementation of `IGeventPatchEvent`.

class GeventWillPatchAllEvent(patch_all_arguments, patch_all_kwargs)

  Bases: `_PatchAllMixin`, `GeventWillPatchEvent`

  Implementation of `IGeventWillPatchAllEvent`.

  ENTRY_POINT_NAME = 'gevent.plugins.monkey.will_patch_all'

    The name of the setuptools entry point that is called when this event is emitted.

class GeventWillPatchEvent(source, target)

  Bases: `GeventPatchEvent`

  Implementation of `IGeventWillPatchEvent`.

class GeventWillPatchModuleEvent(module_name, source, target, items)

  Bases: `GeventWillPatchEvent`

  Implementation of `IGeventWillPatchModuleEvent`.

  ENTRY_POINT_NAME = 'gevent.plugins.monkey.will_patch_module'

    The name of the setuptools entry point that is called when this event is emitted.

class MemoryUsageThresholdExceeded(mem_usage, max_allowed, memory_info)

  Bases: `_AbstractMemoryEvent`

  Implementation of `IMemoryUsageThresholdExceeded`.

class MemoryUsageUnderThreshold(mem_usage, max_allowed, memory_info, max_usage)

  Bases: `_AbstractMemoryEvent`

  Implementation of `IMemoryUsageUnderThreshold`.

class PeriodicMonitorThreadStartedEvent(monitor)

  Bases: `object`

  The implementation of `IPeriodicMonitorThreadStartedEvent`.

  Changed in version 24.11.1: Now actually implements the promised interface.

  ENTRY_POINT_NAME = 'gevent.plugins.hub.periodic_monitor_thread_started'

    The name of the setuptools entry point that is called when this event is emitted.

subscribers = []

  Applications may register for notification of events by appending a callable to the `subscribers` list.

  Each subscriber takes a single argument, which is the event object being published.

  Exceptions raised by subscribers will be propagated without running any remaining subscribers.

  This is an alias for `zope.event.subscribers`; prefer to use that attribute directly.