Patch: When demandimport is disabled the 'test-profile' test fails.

Alejandro Santos alejolp at alejolp.com
Tue Jul 28 22:41:14 CDT 2009


On Tue, Jul 28, 2009 at 10:13 PM, Nicolas Dumazet<nicdumz at gmail.com> wrote:
> 2009/7/29 Alejandro Santos <alejolp at alejolp.com>:
>> +  File "/tmp/hgtests.xStzl7/install/lib/python/mercurial/lsprof.py",
>> line 88, in label
>> +    for k, v in sys.modules.iteritems():
>> +RuntimeError: dictionary changed size during iteration
>> +--profile + output to file failed
>
> I dont understand what causes this behavior in the loop body. Do you
> understand the problem?

This issue was odd since it should have been the other way around: to
be raised when demandimport was actually enabled.

After some debugging, I've found that the email.MIMEAudio module is
the last one iterated before the RuntimeError is raised. And the email
package from Python uses it's own LazyImporter.

Testing on hg-stable shows the same behavior when disabling Hg demandimport.

$ python2.6
Python 2.6.2 (r262:71600, Jun  8 2009, 09:30:33)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import email.MIMEAudio
>>> email.MIMEAudio
<email.LazyImporter object at 0x7fd13ac31e50>
>>> print len(sys.modules)
54
>>> email.MIMEAudio.__file__
'/home/alejo/apps/local/lib/python2.6/email/mime/audio.pyc'
>>> print len(sys.modules)
113


>> -        for k, v in sys.modules.iteritems():
>> +        for k, v in list(sys.modules.iteritems()):
>
>
> We probably want
>   for k, v in sys.modules.items():
> here, don't we?

Yes!

However, it might be better to force the load of all the half-imported
modules, and then use items() to be on the safe side.

I'll resend the patch.

-- 
Alejandro Santos,
alejolp at alejolp.com.ar
http://www.alejolp.com.ar



More information about the Mercurial-devel mailing list