This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sbt
Recipients sbt
Date 2013-06-14.14:59:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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

See also

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]
Date User Action Args
2013-06-14 14:59:39sbtsetrecipients: + sbt
2013-06-14 14:59:39sbtsetmessageid: <>
2013-06-14 14:59:39sbtlinkissue18214 messages
2013-06-14 14:59:38sbtcreate