PATCH: lsprof.py RuntimeError

Alejandro Santos alejolp at alejolp.com
Wed Jul 29 15:33:29 CDT 2009


On crew and hg-stable repos, 'test-profile' test fails when
demandimport is disabled.

Third attempt to fix the Mercurial #1774 issue:

http://mercurial.selenic.com/bts/issue1774

# HG changeset patch
# User Alejandro Santos <alejolp at alejolp.com>
# Date 1248899392 10800
# Node ID d1d8947179b73c338c8199c37b72683bbd141541
# Parent  1eed391889f4e4a4dc441194fafe0e7165abf49d
When demandimport is disabled the 'test-profile' test fails.

diff -r 1eed391889f4 -r d1d8947179b7 mercurial/lsprof.py
--- a/mercurial/lsprof.py	Wed Jul 29 00:20:28 2009 -0300
+++ b/mercurial/lsprof.py	Wed Jul 29 17:29:52 2009 -0300
@@ -85,7 +85,20 @@
     try:
         mname = _fn2mod[code.co_filename]
     except KeyError:
-        for k, v in sys.modules.iteritems():
+        # Force the complete load of all the lazy and on demand modules by
+        # querying one of the module's attribute.
+        #
+        # See Mercurial issue #1774
+        #
+        # We use list(dict.iteritems()) here since we need a list to avoid a
+        # possible RuntimeError when there are partially loaded modules,
+        # (LazyImporter and demandimport).
+
+        for k, v in list(sys.modules.iteritems()):
+            hasattr(v, 'somemissingattr')
+
+        # The same here. list(dict.iteritems()) is what we need.
+        for k, v in list(sys.modules.iteritems()):
             if v is None:
                 continue
             if not hasattr(v, '__file__'):


More information about the Mercurial-devel mailing list