Allow limited PEP 523 plugins. (#2822)

This commit is contained in:
Mark Shannon 2022-10-07 16:42:35 -07:00 committed by GitHub
parent 5cf5c3baae
commit 43af7ba688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 25 deletions

View File

@ -291,42 +291,35 @@ Backwards Compatibility
This PEP is mostly backwards compatible.
This PEP is incompatible with :pep:`523` as the behavior would be undefined,
since the VM has no control over the behavior of :pep:`523` plugins.
There are some compatibility issues with :pep:`523`, as the behavior
of :pep:`523` plugins is outside of the VM's control.
It is up to :pep:`523` plugins to ensure that they respect the semantics
of this PEP. Simple plugins that do not change the state of the VM, and
defer execution to ``_PyEval_EvalFrameDefault()`` should continue to work.
Thus, if ``_PyInterpreterState_SetEvalFrameFunc()`` has been called and has
changed the frame evaluation function, then calling
``sys.monitoring.set_events()``, ``sys.monitoring.set_local_events()``, or
``sys.monitoring.insert_marker`` will raise an exception.
:func:`sys.settrace` and :func:`sys.setprofile` will act as if they were tools
6 and 7 respectively, so can be used along side this PEP.
Likewise, if ``sys.monitoring.set_events()``,
``sys.monitoring.set_local_events()``, or ``sys.monitoring.insert_marker``
has been called, then calling ``_PyInterpreterState_SetEvalFrameFunc()``
will raise an exception.
``sys.settrace`` and ``sys.setprofile`` will act as if they were tools 6 and 7
respectively, so can be used along side this PEP.
This makes ``sys.settrace`` and ``sys.setprofile`` incompatible with :pep:`523`.
Arguably, they already were as the author does not know of any PEP 523 plugin
that supports ``sys.settrace`` or ``sys.setprofile`` correctly.
This PEP merely formalizes that.
This means that :func:`sys.settrace` and :func:`sys.setprofile` may not work
correctly with all :pep:`523` plugins. Although, simple :pep:`523`
plugins, as described above, should be fine.
Performance
-----------
If no events are active, this PEP should have a small positive impact on
performance. Experiments show between 1 and 2% speedup from not supporting
``sys.settrace()`` directly.
:func:`sys.settrace` directly.
The performance of ``sys.settrace()`` will be worse.
The performance of ``sys.setprofile()`` should be better.
However, tools relying on ``sys.settrace()`` and ``sys.setprofile()``
can be made a lot faster by using the API provided by this PEP.
The performance of :func:`sys.settrace` will be worse.
The performance of :func:`sys.setprofile` should be better.
However, tools relying on :func:`sys.settrace` and
:func:`sys.setprofile` can be made a lot faster by using the
API provided by this PEP.
If a small set of events are active, e.g. for a debugger, then the overhead
of callbacks will be orders of magnitudes less than for ``sys.settrace`` and
much cheaper than using :pep:`523`.
of callbacks will be orders of magnitudes less than for :func:`sys.settrace`
and much cheaper than using :pep:`523`.
Coverage tools can be implemented at very low cost,
by returning ``DISABLE`` in all callbacks.