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 xdegaye
Recipients xdegaye
Date 2010-07-13.16:36:10
SpamBayes Score 0.00019661532
Marked as misclassified No
Message-id <1279038973.54.0.16228117882.issue9250@psf.upfronthosting.co.za>
In-reply-to
Content
Python 2.7 - svn revision 82852

Bug description
===============

Test script foo.py
------------------

    #!/usr/bin/env python
    import distutils.core
    import test.regrtest


Exception when running foo.py
-----------------------------

Traceback (most recent call last):
  File "foo.py", line 3, in <module>
    import test.regrtest
  File "/usr/local/lib/python2.7/test/regrtest.py", line 184, in <module>
    for module in sys.modules.itervalues():
RuntimeError: dictionary changed size during iteration


Workaround
==========

Revese the order of the imports in foo.py.


Proposed patch
==============

Root cause: email modules are being imported inside the loop.

The following patch (svn revision 82852) forces the import of the
email modules before the main iteration. These modules have been
lazily imported in email/__init__.py and need to be effectively
imported before updating the __file__ and __path__ attributes.

The patch is also attached to this report.

--- release27-maint/Lib/test/regrtest.py       2010-07-13 18:11:32.000000000 +0200
+++ /usr/local/lib/python2.7/test/regrtest.py   2010-07-13 18:00:52.000000000 +0200
@@ -181,6 +181,12 @@
 # (site.py absolutize them), the __file__ and __path__ will be absolute too.
 # Therefore it is necessary to absolutize manually the __file__ and __path__ of
 # the packages to prevent later imports to fail when the CWD is different.
+
+# Email modules are imported lazily, force their import first.
+if 'email' in sys.modules:
+    [hasattr(sys.modules[name], '__foo__') for name in list(sys.modules)
+                                                if name.startswith('email.')]
+
 for module in sys.modules.itervalues():
     if hasattr(module, '__path__'):
         module.__path__ = [os.path.abspath(path) for path in module.__path__]
History
Date User Action Args
2010-07-13 16:36:13xdegayesetrecipients: + xdegaye
2010-07-13 16:36:13xdegayesetmessageid: <1279038973.54.0.16228117882.issue9250@psf.upfronthosting.co.za>
2010-07-13 16:36:10xdegayelinkissue9250 messages
2010-07-13 16:36:10xdegayecreate