comparison Python/pythonrun.c @ 31057:f69589179c55 legacy-trunk

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.
author Tim Peters <tim.peters@gmail.com>
date Mon, 01 Dec 2003 21:35:27 +0000
parents 86fdf8fe7f17
children 2abc52c3d4c2
comparison
equal deleted inserted replaced
31056:251717566e91 31057:f69589179c55
327 /* drop module references we saved */ 327 /* drop module references we saved */
328 Py_XDECREF(warnings_module); 328 Py_XDECREF(warnings_module);
329 warnings_module = NULL; 329 warnings_module = NULL;
330 330
331 /* Collect garbage. This may call finalizers; it's nice to call these 331 /* 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 */
333 PyGC_Collect(); 343 PyGC_Collect();
334 344
335 /* Destroy all modules */ 345 /* Destroy all modules */
336 PyImport_Cleanup(); 346 PyImport_Cleanup();
337 347
338 /* Collect final garbage. This disposes of cycles created by 348 /* 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
340 PyGC_Collect(); 364 PyGC_Collect();
365 #endif
341 366
342 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */ 367 /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
343 _PyImport_Fini(); 368 _PyImport_Fini();
344 369
345 /* Debugging stuff */ 370 /* Debugging stuff */