New submission from Richard Oudkerk:

Currently when a module is garbage collected its dict is purged by replacing 
all values except __builtins__ by None.  This helps clear things at shutdown. 

But this can cause problems if it occurs *before* shutdown: if we use a 
function defined in a module which has been garbage collected, then that 
function must not depend on any globals, because they will have been purged.

Usually this problem only occurs with programs which manipulate sys.modules.  
For example when setuptools and nose run tests they like to reset sys.modules 
each time.  See for example

  http://bugs.python.org/issue15881

See also

  http://bugs.python.org/issue16718

The trivial patch attached prevents the purging behaviour for modules gc'ed 
before shutdown begins.  Usually garbage collection will end up clearing the 
module's dict anyway.

I checked the count of refs and blocks reported on exit when running a trivial 
program and a full regrtest (which will cause quite a bit of sys.modules 
manipulation).  The difference caused by the patch is minimal.

Without patch:
  do nothing:    [20234 refs, 6582 blocks]
  full regrtest: [92713 refs, 32597 blocks]

With patch:
  do nothing:    [20234 refs, 6582 blocks]
  full regrtest: [92821 refs, 32649 blocks]

----------
files: prevent-purge-before-shutdown.patch
keywords: patch
messages: 191135
nosy: sbt
priority: normal
severity: normal
status: open
title: Stop purging modules which are garbage collected before shutdown
versions: Python 3.4
Added file: http://bugs.python.org/file30583/prevent-purge-before-shutdown.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18214>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to