mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.9] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122120)
This commit is contained in:
parent
54b5e9e9a8
commit
9e9c71d09e
5 changed files with 34 additions and 0 deletions
|
|
@ -56,6 +56,26 @@ Additionally, there are **low-level** APIs for
|
|||
* :ref:`bridge <asyncio-futures>` callback-based libraries and code
|
||||
with async/await syntax.
|
||||
|
||||
.. _asyncio-cli:
|
||||
|
||||
.. rubric:: asyncio REPL
|
||||
|
||||
You can experiment with an ``asyncio`` concurrent context in the REPL:
|
||||
|
||||
.. code-block:: pycon
|
||||
|
||||
$ python -m asyncio
|
||||
asyncio REPL ...
|
||||
Use "await" directly instead of "asyncio.run()".
|
||||
Type "help", "copyright", "credits" or "license" for more information.
|
||||
>>> import asyncio
|
||||
>>> await asyncio.sleep(10, result='hello')
|
||||
'hello'
|
||||
|
||||
.. audit-event:: cpython.run_stdin "" ""
|
||||
|
||||
.. versionchanged:: 3.9.20 (also 3.8.20)
|
||||
Emits audit events.
|
||||
|
||||
.. We use the "rubric" directive here to avoid creating
|
||||
the "Reference" subsection in the TOC.
|
||||
|
|
|
|||
|
|
@ -610,6 +610,11 @@ conflict.
|
|||
This variable can also be modified by Python code using :data:`os.environ`
|
||||
to force inspect mode on program termination.
|
||||
|
||||
.. audit-event:: cpython.run_stdin "" ""
|
||||
|
||||
.. versionchanged:: 3.9.20 (also 3.8.20)
|
||||
Emits audit events.
|
||||
|
||||
|
||||
.. envvar:: PYTHONUNBUFFERED
|
||||
|
||||
|
|
|
|||
|
|
@ -90,6 +90,8 @@ def run(self):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.audit("cpython.run_stdin")
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
asyncio.set_event_loop(loop)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
Fixed missing audit events around interactive use of Python, now also
|
||||
properly firing for ``python -i``, as well as for ``python -m asyncio``. The
|
||||
event in question is ``cpython.run_stdin``.
|
||||
|
|
@ -534,6 +534,10 @@ pymain_repl(PyConfig *config, PyCompilerFlags *cf, int *exitcode)
|
|||
return;
|
||||
}
|
||||
|
||||
if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int res = PyRun_AnyFileFlags(stdin, "<stdin>", cf);
|
||||
*exitcode = (res != 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue