%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
a
�_gP� � @ s d Z ddlmZ ddlmZ ddlZg d�Zej�d�ZG dd� de �Z
G d d
� d
e�Zd[dd�Z
d
d� Zi Zdd� Zdd� Zdd� Zdd� Zdd� Ze� Zdd� Zdd� Zdd� ZG dd � d e�Zd\d"d#�Zd$d%� Zd]d&d'�Zd(d)� Zd*d+� Zd,d-� Z ed^d.d/��Z!ed0d1� �Z"ed2d3� �Z#ed4d5� �Z$ed6d7� �Z%d8d9� Z&ed_d:d;��Z'ed`d<d=��Z(ed>d?� �Z)dadAdB�Z*edbdCdD��Z+edcdEdF��Z,edddGdH��Z-edIdJ� �Z.edKdL� �Z/edMdN� �Z0dOdP� Z1dQdR� Z2dedTdU�Z3dVdW� Z4dXdY� Z5e5� d e4_ e6dZk�re4� dS )fa=
Make the standard library cooperative.
The primary purpose of this module is to carefully patch, in place,
portions of the standard library with gevent-friendly functions that
behave in the same way as the original (at least as closely as possible).
The primary interface to this is the :func:`patch_all` function, which
performs all the available patches. It accepts arguments to limit the
patching to certain modules, but most programs **should** use the
default values as they receive the most wide-spread testing, and some monkey
patches have dependencies on others.
Patching **should be done as early as possible** in the lifecycle of the
program. For example, the main module (the one that tests against
``__main__`` or is otherwise the first imported) should begin with
this code, ideally before any other imports::
from gevent import monkey
monkey.patch_all()
A corollary of the above is that patching **should be done on the main
thread** and **should be done while the program is single-threaded**.
.. tip::
Some frameworks, such as gunicorn, handle monkey-patching for you.
Check their documentation to be sure.
.. warning::
Patching too late can lead to unreliable behaviour (for example, some
modules may still use blocking sockets) or even errors.
.. tip::
Be sure to read the documentation for each patch function to check for
known incompatibilities.
Querying
========
Sometimes it is helpful to know if objects have been monkey-patched, and in
advanced cases even to have access to the original standard library functions. This
module provides functions for that purpose.
- :func:`is_module_patched`
- :func:`is_object_patched`
- :func:`get_original`
.. _plugins:
Plugins and Events
==================
Beginning in gevent 1.3, events are emitted during the monkey patching process.
These events are delivered first to :mod:`gevent.events` subscribers, and then
to `setuptools entry points`_.
The following events are defined. They are listed in (roughly) the order
that a call to :func:`patch_all` will emit them.
- :class:`gevent.events.GeventWillPatchAllEvent`
- :class:`gevent.events.GeventWillPatchModuleEvent`
- :class:`gevent.events.GeventDidPatchModuleEvent`
- :class:`gevent.events.GeventDidPatchBuiltinModulesEvent`
- :class:`gevent.events.GeventDidPatchAllEvent`
Each event class documents the corresponding setuptools entry point name. The
entry points will be called with a single argument, the same instance of
the class that was sent to the subscribers.
You can subscribe to the events to monitor the monkey-patching process and
to manipulate it, for example by raising :exc:`gevent.events.DoNotPatch`.
You can also subscribe to the events to provide additional patching beyond what
gevent distributes, either for additional standard library modules, or
for third-party packages. The suggested time to do this patching is in
the subscriber for :class:`gevent.events.GeventDidPatchBuiltinModulesEvent`.
For example, to automatically patch `psycopg2`_ using `psycogreen`_
when the call to :func:`patch_all` is made, you could write code like this::
# mypackage.py
def patch_psycopg(event):
from psycogreen.gevent import patch_psycopg
patch_psycopg()
In your ``setup.py`` you would register it like this::
from setuptools import setup
setup(
...
entry_points={
'gevent.plugins.monkey.did_patch_builtins': [
'psycopg2 = mypackage:patch_psycopg',
],
},
...
)
For more complex patching, gevent provides a helper method
that you can call to replace attributes of modules with attributes of your
own modules. This function also takes care of emitting the appropriate events.
- :func:`patch_module`
.. _setuptools entry points: http://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins
.. _psycopg2: https://pypi.python.org/pypi/psycopg2
.. _psycogreen: https://pypi.python.org/pypi/psycogreen
Use as a module
===============
Sometimes it is useful to run existing python scripts or modules that
were not built to be gevent aware under gevent. To do so, this module
can be run as the main module, passing the script and its arguments.
For details, see the :func:`main` function.
.. versionchanged:: 1.3b1
Added support for plugins and began emitting will/did patch events.
� )�absolute_import)�print_functionN)� patch_all�patch_builtins� patch_dns�patch_os�patch_queue�patch_select�patch_signal�patch_socket� patch_ssl�patch_subprocess� patch_sys�patch_thread�
patch_time�get_original�is_module_patched�is_object_patched�patch_module�main�winc @ s e Zd ZdZdd� ZdS )�_BadImplementsz6
Raised when ``__implements__`` is incorrect.
c C s t �| d|f � d S )Nz7Module %r has a bad or missing value for __implements__)�AttributeError�__init__)�self�module� r �:/vddos/python/lib/python3.9/site-packages/gevent/monkey.pyr � s �z_BadImplements.__init__N)�__name__�
__module__�__qualname__�__doc__r r r r r r � s r c @ s e Zd ZdZdS )�MonkeyPatchWarningzE
The type of warnings we issue.
.. versionadded:: 1.3a2
N)r r r r! r r r r r"