@@ -1032,9 +1032,25 @@ def find_module(self, fullname, path=None):
10321032 finally :
10331033 del _tls .running
10341034
1035+ blacklisted_msg = (
1036+ '%r is present in the Mitogen importer blacklist, therefore this '
1037+ 'context will not attempt to request it from the master, as the '
1038+ 'request will always be refused.'
1039+ )
1040+ pkg_resources_msg = (
1041+ 'pkg_resources is prohibited from importing __main__, as it causes '
1042+ 'problems in applications whose main module is not designed to be '
1043+ 're-imported by children.'
1044+ )
1045+ absent_msg = (
1046+ 'The Mitogen master process was unable to serve %r. It may be a '
1047+ 'native Python extension, or it may be missing entirely. Check the '
1048+ 'importer debug logs on the master for more information.'
1049+ )
1050+
10351051 def _refuse_imports (self , fullname ):
10361052 if is_blacklisted_import (self , fullname ):
1037- raise ImportError ('Refused: ' + fullname )
1053+ raise ImportError (self . blacklisted_msg % ( fullname ,) )
10381054
10391055 f = sys ._getframe (2 )
10401056 requestee = f .f_globals ['__name__' ]
@@ -1046,7 +1062,7 @@ def _refuse_imports(self, fullname):
10461062 # breaks any app that is not expecting its __main__ to suddenly be
10471063 # sucked over a network and injected into a remote process, like
10481064 # py.test.
1049- raise ImportError ('Refused' )
1065+ raise ImportError (self . pkg_resources_msg )
10501066
10511067 if fullname == 'pbr' :
10521068 # It claims to use pkg_resources to read version information, which
@@ -1106,7 +1122,7 @@ def load_module(self, fullname):
11061122
11071123 ret = self ._cache [fullname ]
11081124 if ret [2 ] is None :
1109- raise ImportError ('Master does not have %r' % (fullname ,))
1125+ raise ImportError (self . absent_msg % (fullname ,))
11101126
11111127 pkg_present = ret [1 ]
11121128 mod = sys .modules .setdefault (fullname , imp .new_module (fullname ))
@@ -1139,14 +1155,14 @@ def get_filename(self, fullname):
11391155 # reveals the module can't be loaded, and so load_module()
11401156 # throws ImportError, on Python 3.x it is still possible for
11411157 # the loader to be called to fetch metadata.
1142- raise ImportError ('master cannot serve %r' % (fullname ,))
1158+ raise ImportError (self . absent_msg % (fullname ,))
11431159 return u'master:' + self ._cache [fullname ][2 ]
11441160
11451161 def get_source (self , fullname ):
11461162 if fullname in self ._cache :
11471163 compressed = self ._cache [fullname ][3 ]
11481164 if compressed is None :
1149- raise ImportError ('master cannot serve %r' % (fullname ,))
1165+ raise ImportError (self . absent_msg % (fullname ,))
11501166
11511167 source = zlib .decompress (self ._cache [fullname ][3 ])
11521168 if PY3 :
0 commit comments