disabled
  7  ˆl–Ým_J
j"TýÆß¸ÛJbÑ¿�þYŒ‚Y²€­‰á<çÌ„b}ïËðÁÊ ;Â   # -*- coding: utf-8 -*-
# Copyright 2018 gevent. See LICENSE for details.
"""
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.

:mod:`zope.event` will be used to provide the functionality of
`notify` and `subscribers`. See :mod:`zope.event.classhandler` for a
simple class-based approach to subscribing to a filtered list of
events, and see `zope.component
<https://zopecomponent.readthedocs.io/en/latest/event.html>`_ for a
much higher-level, flexible system. If you are using one of these
systems, you generally will not want to directly modify `subscribers`.

.. versionadded:: 1.3b1
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


__all__ = [
    'subscribers',

    # monitor thread
    'IEventLoopBlocked',
    'EventLoopBlocked',
    'IMemoryUsageThresholdExceeded',
    'MemoryUsageThresholdExceeded',
    'IMemoryUsageUnderThreshold',
    'MemoryUsageUnderThreshold',

    # Hub
    'IPeriodicMonitorThread',
    'IPeriodicMonitorThreadStartedEvent',
    'PeriodicMonitorThreadStartedEvent',

    # monkey
    'IGeventPatchEvent',
    'GeventPatchEvent',
    'IGeventWillPatchEvent',
    'DoNotPatch',
    'GeventWillPatchEvent',
    'IGeventDidPatchEvent',
    'IGeventWillPatchModuleEvent',
    'GeventWillPatchModuleEvent',
    'IGeventDidPatchModuleEvent',
    'GeventDidPatchModuleEvent',
    'IGeventWillPatchAllEvent',
    'GeventWillPatchAllEvent',
    'IGeventDidPatchBuiltinModulesEvent',
    'GeventDidPatchBuiltinModulesEvent',
    'IGeventDidPatchAllEvent',
    'GeventDidPatchAllEvent',
]

# pylint:disable=no-self-argument,inherit-non-class
import platform

from zope.interface import Interface
from zope.interface import Attribute
from zope.interface import implementer

from zope.event import subscribers
from zope.event import notify

from pkg_resources import iter_entry_points

#: 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.
subscribers = subscribers

try:
    # Cache the platform info. pkg_resources uses
    # platform.machine() for environment markers, and
    # platform.machine() wants to call os.popen('uname'), which is
    # broken on Py2 when the gevent child signal handler is
    # installed. (see test__monkey_sigchild_2.py)
    platform.uname()
except: # pylint:disable=bare-except
    pass
finally:
    del platform

def notify_and_call_entry_points(event):
    notify(event)
    for plugin in iter_entry_points(event.ENTRY_POINT_NAME):
        subscriber = plugin.load()
        subscriber(event)


class IPeriodicMonitorThread(Interface):
    """
    The contract for the periodic monitoring thread that is started
    by the hub.
    """

    def add_monitoring_function(function, period):
        """
        Schedule the *function* to be called approximately every *period* fractional seconds.

        The *function* receives one argument, the hub being monitored. It is called
        in the monitoring thread, *not* the hub thread. It **must not** attempt to
        use the gevent asynchronous API.

        If the *function* is already a monitoring function, then its *period*
        will be updated for future runs.

        If the *period* is ``None``, then the function will be removed.

        A *period* less than or equal to zero is not allowed.
        """

class IPeriodicMonitorThreadStartedEvent(Interface):
    """
    T