Skip to content

Commit b1aa038

Browse files
committed
pythongh-108223: Add [NOGIL] marker to sys.version
If Python is configured with --disable-gil, add " [NOGIL]" suffix to sys.version. It should help users to check if they are running a regular Python build with a GIL, or a custom Python build with the new experimental no GIL. sys.version is commonly requested in bug reports: knowing if Python was configured with --disable-gil should ease debug. Example on Linux with --disable-gil: $ ./python -VV Python 3.13.0a0 (heads/main-dirty:d63972e289, Aug 21 2023, 21:43:45) [GCC 13.2.1 20230728 (Red Hat 13.2.1-1)] [NOGIL]
1 parent d63972e commit b1aa038

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Python/getversion.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66
#include "patchlevel.h"
77

88
static int initialized = 0;
9-
static char version[250];
9+
static char version[258];
1010

1111
void _Py_InitVersion(void)
1212
{
1313
if (initialized) {
1414
return;
1515
}
1616
initialized = 1;
17-
PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
18-
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
17+
#ifdef Py_NOGIL
18+
const char *gil = " [NOGIL]"; // 8 characters
19+
#else
20+
const char *gil = "";
21+
#endif
22+
PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s%s",
23+
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler(), gil);
1924
}
2025

2126
const char *

0 commit comments

Comments
 (0)