Skip to content

Commit d86ab5d

Browse files
authored
[3.10] gh-121957: Emit audit events for python -i and python -m asyncio (GH-122119)
1 parent 48f9d3e commit d86ab5d

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

Doc/library/asyncio.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ 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+
5963
You can experiment with an ``asyncio`` concurrent context in the REPL:
6064

6165
.. code-block:: pycon
@@ -68,6 +72,11 @@ You can experiment with an ``asyncio`` concurrent context in the REPL:
6872
>>> await asyncio.sleep(10, result='hello')
6973
'hello'
7074
75+
.. audit-event:: cpython.run_stdin "" ""
76+
77+
.. versionchanged:: 3.10.15 (also 3.9.20, and 3.8.20)
78+
Emits audit events.
79+
7180
.. We use the "rubric" directive here to avoid creating
7281
the "Reference" subsection in the TOC.
7382

Doc/using/cmdline.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,11 @@ conflict.
626626
This variable can also be modified by Python code using :data:`os.environ`
627627
to force inspect mode on program termination.
628628

629+
.. audit-event:: cpython.run_stdin "" ""
630+
631+
.. versionchanged:: 3.10.15 (also 3.9.20, and 3.8.20)
632+
Emits audit events.
633+
629634

630635
.. envvar:: PYTHONUNBUFFERED
631636

Lib/asyncio/__main__.py

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,10 @@ pymain_repl(PyConfig *config, int *exitcode)
524524
return;
525525
}
526526

527+
if (PySys_Audit("cpython.run_stdin", NULL) < 0) {
528+
return;
529+
}
530+
527531
PyCompilerFlags cf = _PyCompilerFlags_INIT;
528532
int res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
529533
*exitcode = (res != 0);

0 commit comments

Comments
 (0)