Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d7323e

Browse files
committed
Py_Finalize(): disabled the second call of cyclic gc, and added extensive
comments about why both calls to cyclic gc here can cause problems. I'll backport to 2.3 maint. Since the calls were introduced in 2.3, that will be the end of it.
1 parent 85f48e3 commit 1d7323e

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ What's New in Python 2.4 alpha 1?
1212
Core and builtins
1313
-----------------
1414

15+
- At Python shutdown time (Py_Finalize()), 2.3 called cyclic garbage
16+
collection twice, both before and after tearing down modules. The
17+
call after tearing down modules has been disabled, because too much
18+
of Python has been torn down then for __del__ methods and weakref
19+
callbacks to execute sanely. The most common symptom was a sequence
20+
of uninformative messages on stderr when Python shut down, produced
21+
by threads trying to raise exceptions, but unable to report the nature
22+
of their problems because too much of the sys module had already been
23+
destroyed.
24+
1525
- Removed FutureWarnings related to hex/oct literals and conversions
1626
and left shifts. (Thanks to Kalle Svensson for SF patch 849227.)
1727
This addresses most of the remaining semantic changes promised by

Python/pythonrun.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,15 +329,40 @@ Py_Finalize(void)
329329
warnings_module = NULL;
330330

331331
/* Collect garbage. This may call finalizers; it's nice to call these
332-
before all modules are destroyed. */
332+
* before all modules are destroyed.
333+
* XXX If a __del__ or weakref callback is triggered here, and tries to
334+
* XXX import a module, bad things can happen, because Python no
335+
* XXX longer believes it's initialized.
336+
* XXX Fatal Python error: Interpreter not initialized (version mismatch?)
337+
* XXX is easy to provoke that way. I've also seen, e.g.,
338+
* XXX Exception exceptions.ImportError: 'No module named sha'
339+
* XXX in <function callback at 0x008F5718> ignored
340+
* XXX but I'm unclear on exactly how that one happens. In any case,
341+
* XXX I haven't seen a real-life report of either of these.
342+
*/
333343
PyGC_Collect();
334344

335345
/* Destroy all modules */
336346
PyImport_Cleanup();
337347

338348
/* Collect final garbage. This disposes of cycles created by
339-
new-style class definitions, for example. */
349+
* new-style class definitions, for example.
350+
* XXX This is disabled because it caused too many problems. If
351+
* XXX a __del__ or weakref callback triggers here, Python code has
352+
* XXX a hard time running, because even the sys module has been
353+
* XXX cleared out (sys.stdout is gone, sys.excepthook is gone, etc).
354+
* XXX One symptom is a sequence of information-free messages
355+
* XXX coming from threads (if a __del__ or callback is invoked,
356+
* XXX other threads can execute too, and any exception they encounter
357+
* XXX triggers a comedy of errors as subsystem after subsystem
358+
* XXX fails to find what it *expects* to find in sys to help report
359+
* XXX the exception and consequent unexpected failures). I've also
360+
* XXX seen segfaults then, after adding print statements to the
361+
* XXX Python code getting called.
362+
*/
363+
#if 0
340364
PyGC_Collect();
365+
#endif
341366

342367
/* Destroy the database used by _PyImport_{Fixup,Find}Extension */
343368
_PyImport_Fini();

0 commit comments

Comments
 (0)