Skip to content

Commit 336e85f

Browse files
committed
Patch #900727: Add Py_InitializeEx to allow embedding without signals.
1 parent 4d4dfb7 commit 336e85f

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

Doc/api/init.tex

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ \chapter{Initialization, Finalization, and Threads
2323
no return value; it is a fatal error if the initialization fails.
2424
\end{cfuncdesc}
2525

26+
\begin{cfuncdesc}{void}{Py_InitializeEx}{int initsigs}
27+
This function works like \cfunction{Py_Initialize} if
28+
\var{initsigs} is 1. If \var{initsigs} is 0, it skips
29+
initialization registration of signal handlers, which
30+
might be useful when Python is embedded. \versionadded{2.4}
31+
\end{cfuncdesc}
32+
2633
\begin{cfuncdesc}{int}{Py_IsInitialized}{}
2734
Return true (nonzero) when the Python interpreter has been
2835
initialized, false (zero) if not. After \cfunction{Py_Finalize()}

Include/pythonrun.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ PyAPI_FUNC(void) Py_SetPythonHome(char *);
2323
PyAPI_FUNC(char *) Py_GetPythonHome(void);
2424

2525
PyAPI_FUNC(void) Py_Initialize(void);
26+
PyAPI_FUNC(void) Py_InitializeEx(int);
2627
PyAPI_FUNC(void) Py_Finalize(void);
2728
PyAPI_FUNC(int) Py_IsInitialized(void);
2829
PyAPI_FUNC(PyThreadState *) Py_NewInterpreter(void);

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ What's New in Python 2.4 alpha 3?
1212
Core and builtins
1313
-----------------
1414

15+
- Py_InitializeEx has been added.
16+
1517
- Fix the order of application of decorators. The proper order is bottom-up;
1618
the first decorator listed is the last one called.
1719

Python/pythonrun.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ add_flag(int flag, const char *envs)
131131
}
132132

133133
void
134-
Py_Initialize(void)
134+
Py_InitializeEx(int install_sigs)
135135
{
136136
PyInterpreterState *interp;
137137
PyThreadState *tstate;
@@ -208,7 +208,8 @@ Py_Initialize(void)
208208

209209
_PyImportHooks_Init();
210210

211-
initsigs(); /* Signal handling stuff, including initintr() */
211+
if (install_sigs)
212+
initsigs(); /* Signal handling stuff, including initintr() */
212213

213214
initmain(); /* Module __main__ */
214215
if (!Py_NoSiteFlag)
@@ -276,6 +277,13 @@ Py_Initialize(void)
276277
#endif
277278
}
278279

280+
void
281+
Py_Initialize(void)
282+
{
283+
Py_InitializeEx(1);
284+
}
285+
286+
279287
#ifdef COUNT_ALLOCS
280288
extern void dump_counts(void);
281289
#endif

0 commit comments

Comments
 (0)