@@ -138,6 +138,7 @@ precmdline_get_preconfig(_PyPreCmdline *cmdline, const PyPreConfig *config)
138
138
COPY_ATTR (isolated );
139
139
COPY_ATTR (use_environment );
140
140
COPY_ATTR (dev_mode );
141
+ COPY_ATTR (disable_gil );
141
142
142
143
#undef COPY_ATTR
143
144
}
@@ -152,6 +153,7 @@ precmdline_set_preconfig(const _PyPreCmdline *cmdline, PyPreConfig *config)
152
153
COPY_ATTR (isolated );
153
154
COPY_ATTR (use_environment );
154
155
COPY_ATTR (dev_mode );
156
+ COPY_ATTR (disable_gil );
155
157
156
158
#undef COPY_ATTR
157
159
}
@@ -171,6 +173,7 @@ _PyPreCmdline_SetConfig(const _PyPreCmdline *cmdline, PyConfig *config)
171
173
COPY_ATTR (isolated );
172
174
COPY_ATTR (use_environment );
173
175
COPY_ATTR (dev_mode );
176
+ COPY_ATTR (disable_gil );
174
177
COPY_ATTR (warn_default_encoding );
175
178
return _PyStatus_OK ();
176
179
@@ -267,9 +270,24 @@ _PyPreCmdline_Read(_PyPreCmdline *cmdline, const PyPreConfig *preconfig)
267
270
cmdline -> warn_default_encoding = 1 ;
268
271
}
269
272
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
+
270
287
assert (cmdline -> use_environment >= 0 );
271
288
assert (cmdline -> isolated >= 0 );
272
289
assert (cmdline -> dev_mode >= 0 );
290
+ assert (cmdline -> disable_gil >= 0 );
273
291
assert (cmdline -> warn_default_encoding >= 0 );
274
292
275
293
return _PyStatus_OK ();
@@ -300,6 +318,7 @@ _PyPreConfig_InitCompatConfig(PyPreConfig *config)
300
318
config -> coerce_c_locale_warn = 0 ;
301
319
302
320
config -> dev_mode = -1 ;
321
+ config -> disable_gil = -1 ;
303
322
config -> allocator = PYMEM_ALLOCATOR_NOT_SET ;
304
323
#ifdef MS_WINDOWS
305
324
config -> legacy_windows_fs_encoding = -1 ;
@@ -386,6 +405,7 @@ preconfig_copy(PyPreConfig *config, const PyPreConfig *config2)
386
405
COPY_ATTR (use_environment );
387
406
COPY_ATTR (configure_locale );
388
407
COPY_ATTR (dev_mode );
408
+ COPY_ATTR (disable_gil );
389
409
COPY_ATTR (coerce_c_locale );
390
410
COPY_ATTR (coerce_c_locale_warn );
391
411
COPY_ATTR (utf8_mode );
@@ -433,6 +453,7 @@ _PyPreConfig_AsDict(const PyPreConfig *config)
433
453
SET_ITEM_INT (legacy_windows_fs_encoding );
434
454
#endif
435
455
SET_ITEM_INT (dev_mode );
456
+ SET_ITEM_INT (disable_gil );
436
457
SET_ITEM_INT (allocator );
437
458
return dict ;
438
459
@@ -456,6 +477,7 @@ _PyPreConfig_GetConfig(PyPreConfig *preconfig, const PyConfig *config)
456
477
COPY_ATTR (isolated );
457
478
COPY_ATTR (use_environment );
458
479
COPY_ATTR (dev_mode );
480
+ COPY_ATTR (disable_gil );
459
481
460
482
#undef COPY_ATTR
461
483
}
0 commit comments