Skip to content

Commit

Permalink
pythongh-108223: Add [NOGIL] marker to sys.version
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
vstinner committed Aug 21, 2023
1 parent d63972e commit b1aa038
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Python/getversion.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
#include "patchlevel.h"

static int initialized = 0;
static char version[250];
static char version[258];

void _Py_InitVersion(void)
{
if (initialized) {
return;
}
initialized = 1;
PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s",
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler());
#ifdef Py_NOGIL
const char *gil = " [NOGIL]"; // 8 characters
#else
const char *gil = "";
#endif
PyOS_snprintf(version, sizeof(version), "%.80s (%.80s) %.80s%s",
PY_VERSION, Py_GetBuildInfo(), Py_GetCompiler(), gil);
}

const char *
Expand Down

0 comments on commit b1aa038

Please sign in to comment.