Skip to content

Commit 9e9c71d

Browse files
authored
[3.9] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122120)
1 parent 54b5e9e commit 9e9c71d

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
@@ -56,6 +56,26 @@ Additionally, there are **low-level** APIs for
5656
* :ref:`bridge <asyncio-futures>` callback-based libraries and code
5757
with async/await syntax.
5858

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

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

Doc/using/cmdline.rst

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

613+
.. audit-event:: cpython.run_stdin "" ""
614+
615+
.. versionchanged:: 3.9.20 (also 3.8.20)
616+
Emits audit events.
617+
613618

614619
.. envvar:: PYTHONUNBUFFERED
615620

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
@@ -534,6 +534,10 @@ pymain_repl(PyConfig *config, PyCompilerFlags *cf, int *exitcode)
534534
return;
535535
}
536536

537+
if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
538+
return;
539+
}
540+
537541
int res = PyRun_AnyFileFlags(stdin, "<stdin>", cf);
538542
*exitcode = (res != 0);
539543
}

0 commit comments

Comments
 (0)