@@ -138,6 +138,7 @@ precmdline_get_preconfig(_PyPreCmdline *cmdline, const PyPreConfig *config)
138138 COPY_ATTR (isolated );
139139 COPY_ATTR (use_environment );
140140 COPY_ATTR (dev_mode );
141+ COPY_ATTR (disable_gil );
141142
142143#undef COPY_ATTR
143144}
@@ -152,6 +153,7 @@ precmdline_set_preconfig(const _PyPreCmdline *cmdline, PyPreConfig *config)
152153 COPY_ATTR (isolated );
153154 COPY_ATTR (use_environment );
154155 COPY_ATTR (dev_mode );
156+ COPY_ATTR (disable_gil );
155157
156158#undef COPY_ATTR
157159}
@@ -171,6 +173,7 @@ _PyPreCmdline_SetConfig(const _PyPreCmdline *cmdline, PyConfig *config)
171173 COPY_ATTR (isolated );
172174 COPY_ATTR (use_environment );
173175 COPY_ATTR (dev_mode );
176+ COPY_ATTR (disable_gil );
174177 COPY_ATTR (warn_default_encoding );
175178 return _PyStatus_OK ();
176179
@@ -267,9 +270,24 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, const PyPreConfig *preconfig)
267270 cmdline -> warn_default_encoding = 1 ;
268271 }
269272
273+ /* GIL */
274+ if (cmdline -> disable_gil < 0 ) {
275+ const char * env = NULL ;
276+ if (_Py_get_xoption (& cmdline -> xoptions , L"nogil" )) {
277+ cmdline -> disable_gil = 1 ;
278+ }
279+ else if ((env = _Py_GetEnv (cmdline -> use_environment , "PYTHONGIL" ))) {
280+ cmdline -> disable_gil = (strcmp (env , "0" ) == 0 );
281+ }
282+ else {
283+ cmdline -> disable_gil = 0 ;
284+ }
285+ }
286+
270287 assert (cmdline -> use_environment >= 0 );
271288 assert (cmdline -> isolated >= 0 );
272289 assert (cmdline -> dev_mode >= 0 );
290+ assert (cmdline -> disable_gil >= 0 );
273291 assert (cmdline -> warn_default_encoding >= 0 );
274292
275293 return _PyStatus_OK ();
@@ -300,6 +318,7 @@ _PyPreConfig_InitCompatConfig(PyPreConfig *config)
300318 config -> coerce_c_locale_warn = 0 ;
301319
302320 config -> dev_mode = -1 ;
321+ config -> disable_gil = -1 ;
303322 config -> allocator = PYMEM_ALLOCATOR_NOT_SET ;
304323#ifdef MS_WINDOWS
305324 config -> legacy_windows_fs_encoding = -1 ;
@@ -386,6 +405,7 @@ preconfig_copy(PyPreConfig *config, const PyPreConfig *config2)
386405 COPY_ATTR (use_environment );
387406 COPY_ATTR (configure_locale );
388407 COPY_ATTR (dev_mode );
408+ COPY_ATTR (disable_gil );
389409 COPY_ATTR (coerce_c_locale );
390410 COPY_ATTR (coerce_c_locale_warn );
391411 COPY_ATTR (utf8_mode );
@@ -433,6 +453,7 @@ _PyPreConfig_AsDict(const PyPreConfig *config)
433453 SET_ITEM_INT (legacy_windows_fs_encoding );
434454#endif
435455 SET_ITEM_INT (dev_mode );
456+ SET_ITEM_INT (disable_gil );
436457 SET_ITEM_INT (allocator );
437458 return dict ;
438459
@@ -456,6 +477,7 @@ _PyPreConfig_GetConfig(PyPreConfig *preconfig, const PyConfig *config)
456477 COPY_ATTR (isolated );
457478 COPY_ATTR (use_environment );
458479 COPY_ATTR (dev_mode );
480+ COPY_ATTR (disable_gil );
459481
460482#undef COPY_ATTR
461483}
0 commit comments