Skip to content

Commit 16ebbaa

Browse files
committed
Some cleanup.
1 parent 1ccb1db commit 16ebbaa

3 files changed

Lines changed: 68 additions & 50 deletions

File tree

Doc/c-api/interp-lifecycle.rst

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
.. _initialization:
44

5-
*******************************************
65
Interpreter Initialization and Finalization
7-
*******************************************
6+
===========================================
87

98
See :ref:`Python Initialization Configuration <init-config>` for details
109
on how to configure the interpreter prior to initialization.
1110

1211
.. _pre-init-safe:
1312

1413
Before Python Initialization
15-
============================
14+
----------------------------
1615

1716
In an application embedding Python, the :c:func:`Py_Initialize` function must
1817
be called before using any other Python/C API functions; with the exception of
@@ -82,7 +81,7 @@ The following functions can be safely called before Python is initialized:
8281
.. _global-conf-vars:
8382

8483
Global configuration variables
85-
==============================
84+
------------------------------
8685

8786
Python has variables for the global configuration to control different features
8887
and options. By default, these flags are controlled by :ref:`command line
@@ -92,6 +91,7 @@ When a flag is set by an option, the value of the flag is the number of times
9291
that the option was set. For example, ``-b`` sets :c:data:`Py_BytesWarningFlag`
9392
to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
9493

94+
9595
.. c:var:: int Py_BytesWarningFlag
9696
9797
This API is kept for backward compatibility: setting
@@ -106,6 +106,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
106106

107107
.. deprecated-removed:: 3.12 3.15
108108

109+
109110
.. c:var:: int Py_DebugFlag
110111
111112
This API is kept for backward compatibility: setting
@@ -120,6 +121,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
120121

121122
.. deprecated-removed:: 3.12 3.15
122123

124+
123125
.. c:var:: int Py_DontWriteBytecodeFlag
124126
125127
This API is kept for backward compatibility: setting
@@ -134,6 +136,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
134136

135137
.. deprecated-removed:: 3.12 3.15
136138

139+
137140
.. c:var:: int Py_FrozenFlag
138141
139142
This API is kept for backward compatibility: setting
@@ -144,6 +147,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
144147

145148
.. deprecated-removed:: 3.12 3.15
146149

150+
147151
.. c:var:: int Py_HashRandomizationFlag
148152
149153
This API is kept for backward compatibility: setting
@@ -159,6 +163,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
159163

160164
.. deprecated-removed:: 3.12 3.15
161165

166+
162167
.. c:var:: int Py_IgnoreEnvironmentFlag
163168
164169
This API is kept for backward compatibility: setting
@@ -172,6 +177,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
172177

173178
.. deprecated-removed:: 3.12 3.15
174179

180+
175181
.. c:var:: int Py_InspectFlag
176182
177183
This API is kept for backward compatibility: setting
@@ -187,6 +193,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
187193

188194
.. deprecated-removed:: 3.12 3.15
189195

196+
190197
.. c:var:: int Py_InteractiveFlag
191198
192199
This API is kept for backward compatibility: setting
@@ -197,6 +204,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
197204

198205
.. deprecated-removed:: 3.12 3.15
199206

207+
200208
.. c:var:: int Py_IsolatedFlag
201209
202210
This API is kept for backward compatibility: setting
@@ -212,6 +220,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
212220

213221
.. deprecated-removed:: 3.12 3.15
214222

223+
215224
.. c:var:: int Py_LegacyWindowsFSEncodingFlag
216225
217226
This API is kept for backward compatibility: setting
@@ -231,6 +240,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
231240

232241
.. deprecated-removed:: 3.12 3.15
233242

243+
234244
.. c:var:: int Py_LegacyWindowsStdioFlag
235245
236246
This API is kept for backward compatibility: setting
@@ -249,6 +259,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
249259

250260
.. deprecated-removed:: 3.12 3.15
251261

262+
252263
.. c:var:: int Py_NoSiteFlag
253264
254265
This API is kept for backward compatibility: setting
@@ -264,6 +275,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
264275

265276
.. deprecated-removed:: 3.12 3.15
266277

278+
267279
.. c:var:: int Py_NoUserSiteDirectory
268280
269281
This API is kept for backward compatibility: setting
@@ -278,6 +290,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
278290

279291
.. deprecated-removed:: 3.12 3.15
280292

293+
281294
.. c:var:: int Py_OptimizeFlag
282295
283296
This API is kept for backward compatibility: setting
@@ -289,6 +302,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
289302

290303
.. deprecated-removed:: 3.12 3.15
291304

305+
292306
.. c:var:: int Py_QuietFlag
293307
294308
This API is kept for backward compatibility: setting
@@ -303,6 +317,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
303317

304318
.. deprecated-removed:: 3.12 3.15
305319

320+
306321
.. c:var:: int Py_UnbufferedStdioFlag
307322
308323
This API is kept for backward compatibility: setting
@@ -316,6 +331,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
316331

317332
.. deprecated-removed:: 3.12 3.15
318333

334+
319335
.. c:var:: int Py_VerboseFlag
320336
321337
This API is kept for backward compatibility: setting
@@ -334,8 +350,7 @@ to 1 and ``-bb`` sets :c:data:`Py_BytesWarningFlag` to 2.
334350

335351

336352
Initializing and finalizing the interpreter
337-
===========================================
338-
353+
-------------------------------------------
339354

340355
.. c:function:: void Py_Initialize()
341356
@@ -555,9 +570,9 @@ Initializing and finalizing the interpreter
555570
556571
.. versionadded:: 3.13
557572
558-
Process-wide parameters
559-
=======================
560573
574+
Process-wide parameters
575+
-----------------------
561576
562577
.. c:function:: void Py_SetProgramName(const wchar_t *name)
563578
@@ -755,6 +770,7 @@ Process-wide parameters
755770
756771
.. deprecated-removed:: 3.11 3.15
757772
773+
758774
.. _cautions-regarding-runtime-finalization:
759775
760776
Cautions regarding runtime finalization

Doc/c-api/subinterpreters.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
433433
.. _advanced-debugging:
434434
435435
Advanced Debugger Support
436-
=========================
436+
-------------------------
437437
438438
These functions are only intended to be used by advanced debugging tools.
439439

Doc/c-api/threads.rst

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,45 @@ to be released to attach their thread state, allowing true multi-core parallelis
109109
For example, the standard :mod:`zlib` and :mod:`hashlib` modules detach the
110110
:term:`thread state <attached thread state>` when compressing or hashing data.
111111

112+
APIs
113+
^^^^
114+
115+
The following macros are normally used without a trailing semicolon; look for
116+
example usage in the Python source distribution.
117+
118+
.. note::
119+
120+
These macros are still necessary on the :term:`free-threaded build` to prevent
121+
deadlocks.
122+
123+
.. c:macro:: Py_BEGIN_ALLOW_THREADS
124+
125+
This macro expands to ``{ PyThreadState *_save; _save = PyEval_SaveThread();``.
126+
Note that it contains an opening brace; it must be matched with a following
127+
:c:macro:`Py_END_ALLOW_THREADS` macro. See above for further discussion of this
128+
macro.
129+
130+
131+
.. c:macro:: Py_END_ALLOW_THREADS
132+
133+
This macro expands to ``PyEval_RestoreThread(_save); }``. Note that it contains
134+
a closing brace; it must be matched with an earlier
135+
:c:macro:`Py_BEGIN_ALLOW_THREADS` macro. See above for further discussion of
136+
this macro.
137+
138+
139+
.. c:macro:: Py_BLOCK_THREADS
140+
141+
This macro expands to ``PyEval_RestoreThread(_save);``: it is equivalent to
142+
:c:macro:`Py_END_ALLOW_THREADS` without the closing brace.
143+
144+
145+
.. c:macro:: Py_UNBLOCK_THREADS
146+
147+
This macro expands to ``_save = PyEval_SaveThread();``: it is equivalent to
148+
:c:macro:`Py_BEGIN_ALLOW_THREADS` without the opening brace and variable
149+
declaration.
150+
112151

113152
.. _gilstate:
114153

@@ -178,6 +217,7 @@ the :term:`thread state` is targeting the correct interpreter::
178217
PyThreadState_Clear(tstate);
179218
PyThreadState_DeleteCurrent();
180219

220+
181221
.. _fork-and-threads:
182222

183223
Cautions about fork()
@@ -318,45 +358,6 @@ C extensions.
318358
thread if the runtime is finalizing.
319359
320360
321-
Releasing the GIL
322-
-----------------
323-
324-
The following macros are normally used without a trailing semicolon; look for
325-
example usage in the Python source distribution.
326-
327-
.. note::
328-
329-
These macros are still necessary on the :term:`free-threaded build` to prevent
330-
deadlocks.
331-
332-
.. c:macro:: Py_BEGIN_ALLOW_THREADS
333-
334-
This macro expands to ``{ PyThreadState *_save; _save = PyEval_SaveThread();``.
335-
Note that it contains an opening brace; it must be matched with a following
336-
:c:macro:`Py_END_ALLOW_THREADS` macro. See above for further discussion of this
337-
macro.
338-
339-
340-
.. c:macro:: Py_END_ALLOW_THREADS
341-
342-
This macro expands to ``PyEval_RestoreThread(_save); }``. Note that it contains
343-
a closing brace; it must be matched with an earlier
344-
:c:macro:`Py_BEGIN_ALLOW_THREADS` macro. See above for further discussion of
345-
this macro.
346-
347-
348-
.. c:macro:: Py_BLOCK_THREADS
349-
350-
This macro expands to ``PyEval_RestoreThread(_save);``: it is equivalent to
351-
:c:macro:`Py_END_ALLOW_THREADS` without the closing brace.
352-
353-
354-
.. c:macro:: Py_UNBLOCK_THREADS
355-
356-
This macro expands to ``_save = PyEval_SaveThread();``: it is equivalent to
357-
:c:macro:`Py_BEGIN_ALLOW_THREADS` without the opening brace and variable
358-
declaration.
359-
360361
GIL-state APIs
361362
--------------
362363
@@ -626,7 +627,7 @@ Low-level APIs
626627
627628
628629
Asynchronous Notifications
629-
--------------------------
630+
==========================
630631
631632
A mechanism is provided to make asynchronous notifications to the main
632633
interpreter thread. These notifications take the form of a function
@@ -708,7 +709,8 @@ pointer and a void pointer argument.
708709
709710
.. versionchanged:: 3.7
710711
The type of the *id* parameter changed from :c:expr:`long` to
711-
:c:expr:`unsigned long`.
712+
:c:expr:`unsigned long`
713+
.
712714
713715
.. _thread-local-storage:
714716

0 commit comments

Comments
 (0)