Skip to content

Commit 1fb69b3

Browse files
authored
[3.8] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122121)
1 parent 5505b91 commit 1fb69b3

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

Doc/library/asyncio.rst

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ Additionally, there are **low-level** APIs for
5757
* :ref:`bridge <asyncio-futures>` callback-based libraries and code
5858
with async/await syntax.
5959

60+
.. _asyncio-cli:
61+
62+
.. rubric:: asyncio REPL
63+
64+
You can experiment with an ``asyncio`` concurrent context in the REPL:
65+
66+
.. code-block:: pycon
67+
68+
$ python -m asyncio
69+
asyncio REPL ...
70+
Use "await" directly instead of "asyncio.run()".
71+
Type "help", "copyright", "credits" or "license" for more information.
72+
>>> import asyncio
73+
>>> await asyncio.sleep(10, result='hello')
74+
'hello'
75+
76+
.. audit-event:: cpython.run_stdin "" ""
77+
78+
.. versionchanged:: 3.8.20
79+
Emits audit events.
6080

6181
.. We use the "rubric" directive here to avoid creating
6282
the "Reference" subsection in the TOC.

Doc/using/cmdline.rst

+5
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,11 @@ conflict.
597597
This variable can also be modified by Python code using :data:`os.environ`
598598
to force inspect mode on program termination.
599599

600+
.. audit-event:: cpython.run_stdin "" ""
601+
602+
.. versionchanged:: 3.8.20
603+
Emits audit events.
604+
600605

601606
.. envvar:: PYTHONUNBUFFERED
602607

Lib/asyncio/__main__.py

+2
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ def run(self):
9090

9191

9292
if __name__ == '__main__':
93+
sys.audit("cpython.run_stdin")
94+
9395
loop = asyncio.new_event_loop()
9496
asyncio.set_event_loop(loop)
9597

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed missing audit events around interactive use of Python, now also
2+
properly firing for ``python -i``, as well as for ``python -m asyncio``. The
3+
event in question is ``cpython.run_stdin``.

Modules/main.c

+4
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,10 @@ pymain_repl(PyConfig *config, PyCompilerFlags *cf, int *exitcode)
546546
return;
547547
}
548548

549+
if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
550+
return;
551+
}
552+
549553
int res = PyRun_AnyFileFlags(stdin, "<stdin>", cf);
550554
*exitcode = (res != 0);
551555
}

0 commit comments

Comments
 (0)