class IGeventPatchEvent(Interface): """ The root for all monkey-patch events gevent emits. """ source = Attribute("The source object containing the patches.") target = Attribute("The destination object to be patched.")
class IGeventWillPatchAllEvent(IGeventWillPatchEvent): """ An event emitted *before* gevent begins patching the system. Following this event will be a series of `IGeventWillPatchModuleEvent` and `IGeventDidPatchModuleEvent` for each patched module. Once the gevent builtin modules have been processed, `IGeventDidPatchBuiltinModulesEvent` will be emitted. Processing this event is an ideal time for third-party modules to be imported and patched (which may trigger its own will/did patch module events). Finally, a `IGeventDidPatchAllEvent` will be sent. If a subscriber to this event raises `DoNotPatch`, no patching will be done. The *source* and *target* attributes have undefined values. """ patch_all_arguments = Attribute( "A dictionary of all the arguments to `gevent.monkey.patch_all`. " "This dictionary should not be modified. ") patch_all_kwargs = Attribute( "A dictionary of the extra arguments to `gevent.monkey.patch_all`. " "This dictionary should not be modified. ") def will_patch_module(module_name): """
class IEventLoopBlocked(Interface): """ The event emitted when the event loop is blocked. This event is emitted in the monitor thread. """ greenlet = Attribute("The greenlet that appeared to be blocking the loop.") blocking_time = Attribute("The approximate time in seconds the loop has been blocked.") info = Attribute("A sequence of string lines providing extra info.")
class IGeventWillPatchModuleEvent(IGeventWillPatchEvent): """ An event emitted *before* gevent begins patching a specific module. Both *source* and *target* attributes are module objects. """ module_name = Attribute("The name of the module being patched. " "This is the same as ``target.__name__``.") target_item_names = Attribute("The list of item names to patch. " "This can be modified in place with caution.")
class IGeventDidPatchBuiltinModulesEvent(IGeventDidPatchEvent): """ Event emitted *after* the builtin modules have been patched. The values of the *source* and *target* attributes are undefined. """ patch_all_arguments = Attribute( "A dictionary of all the arguments to `gevent.monkey.patch_all`. " "This dictionary should not be modified. ") patch_all_kwargs = Attribute( "A dictionary of the extra arguments to `gevent.monkey.patch_all`. " "This dictionary should not be modified. ")
class IMemoryUsageThresholdExceeded(Interface): """ The event emitted when the memory usage threshold is exceeded. This event is emitted only while memory continues to grow above the threshold. Only if the condition or stabilized is corrected (memory usage drops) will the event be emitted in the future. This event is emitted in the monitor thread. """ mem_usage = Attribute("The current process memory usage, in bytes.") max_allowed = Attribute("The maximum allowed memory usage, in bytes.") memory_info = Attribute("The tuple of memory usage stats return by psutil.")
class IGeventDidPatchModuleEvent(IGeventDidPatchEvent): """ An event emitted *after* gevent has completed patching a specific module. """ module_name = Attribute("The name of the module being patched. " "This is the same as ``target.__name__``.")
class IPeriodicMonitorThreadStartedEvent(Interface): """ The event emitted when a hub starts a periodic monitoring thread. You can use this event to add additional monitoring functions. """ monitor = Attribute("The instance of `IPeriodicMonitorThread` that was started.")
class IMemoryUsageUnderThreshold(Interface): """ The event emitted when the memory usage drops below the threshold after having previously been above it. This event is emitted only the first time memory usage is detected to be below the threshold after having previously been above it. If memory usage climbs again, a `IMemoryUsageThresholdExceeded` event will be broadcast, and then this event could be broadcast again. This event is emitted in the monitor thread. """ mem_usage = Attribute("The current process memory usage, in bytes.") max_allowed = Attribute("The maximum allowed memory usage, in bytes.") max_memory_usage = Attribute("The memory usage that caused the previous " "IMemoryUsageThresholdExceeded event.") memory_info = Attribute("The tuple of memory usage stats return by psutil.")
class IGeventDidPatchBuiltinModulesEvent(IGeventDidPatchEvent): """ Event emitted *after* the builtin modules have been patched. If you're going to monkey-patch a third-party library, this is usually the event to listen for. The values of the *source* and *target* attributes are undefined. """ patch_all_arguments = Attribute( "A dictionary of all the arguments to `gevent.monkey.patch_all`. " "This dictionary should not be modified. " ) patch_all_kwargs = Attribute( "A dictionary of the extra arguments to `gevent.monkey.patch_all`. " "This dictionary should not be modified. " )
class ILoop(Interface): """ The common interface expected for all event loops. .. caution:: This is an internal, low-level interface. It may change between minor versions of gevent. .. rubric:: Watchers The methods that create event loop watchers are `io`, `timer`, `signal`, `idle`, `prepare`, `check`, `fork`, `async_`, `child`, `stat`. These all return various types of :class:`IWatcher`. All of those methods have one or two common arguments. *ref* is a boolean saying whether the event loop is allowed to exit even if this watcher is still started. *priority* is event loop specific. """ default = Attribute("Boolean indicating whether this is the default loop") approx_timer_resolution = Attribute( "Floating point number of seconds giving (approximately) the minimum " "resolution of a timer (and hence the minimun value the sleep can sleep for). " "On libuv, this is fixed by the library, but on libev it is just a guess " "and the actual value is system dependent.") def run(nowait=False, once=False): """ Run the event loop. This is usually called automatically by the hub greenlet, but in special cases (when the hub is *not* running) you can use this to control how the event loop runs (for example, to integrate it with another event loop). """ def now(): """ now() -> float Return the loop's notion of the current time. This may not necessarily be related to :func:`time.time` (it may have a different starting point), but it must be expressed in fractional seconds (the same *units* used by :func:`time.time`). """ def update_now(): """ Update the loop's notion of the current time. .. versionadded:: 1.3 In the past, this available as ``update``. This is still available as an alias but will be removed in the future. """ def destroy(): """ Clean up resources used by this loop. If you create loops (especially loops that are not the default) you *should* call this method when you are done with the loop. .. caution:: As an implementation note, the libev C loop implementation has a finalizer (``__del__``) that destroys the object, but the libuv and libev CFFI implementations do not. The C implementation may change. """ def io(fd, events, ref=True, priority=None): """ Create and return a new IO watcher for the given *fd*. *events* is a bitmask specifying which events to watch for. 1 means read, and 2 means write. """ def timer(after, repeat=0.0, ref=True, priority=None): """ Create and return a timer watcher that will fire after *after* seconds. If *repeat* is given, the timer will continue to fire every *repeat* seconds. """ def signal(signum, ref=True, priority=None): """ Create and return a signal watcher for the signal *signum*, one of the constants defined in :mod:`signal`. This is platform and event loop specific. """ def idle(ref=True, priority=None): """ Create and return a watcher that fires when the event loop is idle. """ def prepare(ref=True, priority=None): """ Create and return a watcher that fires before the event loop polls for IO. .. caution:: This method is not supported by libuv. """ def check(ref=True, priority=None): """ Create and return a watcher that fires after the event loop polls for IO. """ def fork(ref=True, priority=None): """ Create a watcher that fires when the process forks. Availability: POSIX """ def async_(ref=True, priority=None): """ Create a watcher that fires when triggered, possibly from another thread. .. versionchanged:: 1.3 This was previously just named ``async``; for compatibility with Python 3.7 where ``async`` is a keyword it was renamed. On older versions of Python the old name is still around, but it will be removed in the future. """ if sys.platform != "win32": def child(pid, trace=0, ref=True): """ Create a watcher that fires for events on the child with process ID *pid*. This is platform specific and not available on Windows. """ def stat(path, interval=0.0, ref=True, priority=None): """ Create a watcher that monitors the filesystem item at *path*. If the operating system doesn't support event notifications from the filesystem, poll for changes every *interval* seconds. """ def run_callback(func, *args): """