Skip to content

Commit e2335fd

Browse files
committed
Document gc.enable_parallel(N) strict re-enable contract in docstring
Phase 5.1.5 changed observable API behaviour: enable_parallel(N) called while parallel GC is already enabled with a *different* N now raises RuntimeError instead of silently keeping the old N. The docstring did not mention this. A user calling enable_parallel twice in real code would hit the exception with no documented explanation. Also document the adaptive worker count introduced in Phase 5.3: num_workers is the upper bound; the controller dynamically adjusts the active count per collection between 2 and num_workers via a biased constrained random walk. Argument Clinic regenerated (Modules/clinic/gcmodule.c.h). Verified: docstring visible via gc.enable_parallel.__doc__ after rebuild; full test suite still green.
1 parent 5501b73 commit e2335fd

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

Modules/clinic/gcmodule.c.h

Lines changed: 14 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/gcmodule.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,12 +503,21 @@ Enable parallel garbage collection with the specified number of workers.
503503
504504
num_workers must be >= 2 (one coordinator + workers).
505505
506+
If parallel GC is already enabled with a *different* num_workers, raises
507+
RuntimeError; call gc.disable_parallel() first. Calling enable_parallel
508+
again with the same num_workers (after disable_parallel) restarts the
509+
existing thread pool without re-initialisation.
510+
511+
The collector dynamically adjusts the active worker count between 2 and
512+
num_workers per collection (biased constrained random walk); num_workers
513+
is the upper bound.
514+
506515
Available in all GIL-based builds (parallel GC is built-in).
507516
[clinic start generated code]*/
508517

509518
static PyObject *
510519
gc_enable_parallel_impl(PyObject *module, int num_workers)
511-
/*[clinic end generated code: output=073661d508bcbcd3 input=68c108dd877213c9]*/
520+
/*[clinic end generated code: output=073661d508bcbcd3 input=eb06a8b394b65504]*/
512521
{
513522
#if defined(Py_GIL_DISABLED) && defined(Py_PARALLEL_GC)
514523
// FTP (free-threading) parallel GC
@@ -636,7 +645,7 @@ Available in all GIL-based builds (parallel GC is built-in).
636645

637646
static PyObject *
638647
gc_disable_parallel_impl(PyObject *module)
639-
/*[clinic end generated code: output=ad7defd925ecd9b6 input=912e72cb61fee6fe]*/
648+
/*[clinic end generated code: output=ad7defd925ecd9b6 input=45a7c611a9b73b3b]*/
640649
{
641650
#if defined(Py_GIL_DISABLED) && defined(Py_PARALLEL_GC)
642651
// FTP (free-threading) parallel GC
@@ -699,7 +708,7 @@ Available in all GIL-based builds (parallel GC is built-in).
699708

700709
static PyObject *
701710
gc_get_parallel_config_impl(PyObject *module)
702-
/*[clinic end generated code: output=1560c2e1d57859e5 input=21e77c05e10fa9a2]*/
711+
/*[clinic end generated code: output=1560c2e1d57859e5 input=62175e9fd1614ca4]*/
703712
{
704713
PyObject *result = PyDict_New();
705714
if (result == NULL) {
@@ -790,7 +799,7 @@ Available in all GIL-based builds (parallel GC is built-in).
790799

791800
static PyObject *
792801
gc_get_parallel_stats_impl(PyObject *module)
793-
/*[clinic end generated code: output=bdc0714efc1df08c input=10079e4be8230ed3]*/
802+
/*[clinic end generated code: output=bdc0714efc1df08c input=7ac8786257fceb3c]*/
794803
{
795804
#if defined(Py_GIL_DISABLED) && defined(Py_PARALLEL_GC)
796805
// FTP (free-threading) parallel GC

0 commit comments

Comments
 (0)