From e8c40cb72245ac7271e61c1b40f5812a8f041fcf Mon Sep 17 00:00:00 2001 From: Neil Schemenauer Date: Wed, 31 Oct 2001 23:09:35 +0000 Subject: [PATCH] Make the gc.collect() function respect the collection lock. This fixes SF bug 476129: "gc.collect sometimes hangs". --- Modules/gcmodule.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index ed846cc78a2..0badc23a4d3 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -548,10 +548,17 @@ gc_collect(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, ":collect")) /* check no args */ return NULL; - generation = 2; - gc_list_merge(&_PyGC_generation0, &generation2); - gc_list_merge(&generation1, &generation2); - n = collect(&generation2, &generation2); + if (collecting) { + n = 0; /* already collecting, don't do anything */ + } + else { + collecting = 1; + generation = 2; + gc_list_merge(&_PyGC_generation0, &generation2); + gc_list_merge(&generation1, &generation2); + n = collect(&generation2, &generation2); + collecting = 0; + } return Py_BuildValue("l", n); }