issue #155: core: ensure reused Importer gets new Context reference.

More hacky layering violations.. force Importer's _context attribute to
our new parent.
pull/167/head
David Wilson 7 years ago
parent cd5b37ea5b
commit 2cf9edc895

@ -1397,22 +1397,26 @@ class ExternalContext(object):
if debug: if debug:
enable_debug_logging() enable_debug_logging()
def _setup_importer(self, core_src_fd, whitelist, blacklist): def _setup_importer(self, importer, core_src_fd, whitelist, blacklist):
if core_src_fd: if not importer:
fp = os.fdopen(101, 'r', 1) if core_src_fd:
try: fp = os.fdopen(101, 'r', 1)
core_size = int(fp.readline()) try:
core_src = fp.read(core_size) core_size = int(fp.readline())
# Strip "ExternalContext.main()" call from last line. core_src = fp.read(core_size)
core_src = '\n'.join(core_src.splitlines()[:-1]) # Strip "ExternalContext.main()" call from last line.
finally: core_src = '\n'.join(core_src.splitlines()[:-1])
fp.close() finally:
else: fp.close()
core_src = None else:
core_src = None
self.importer = Importer(self.router, self.parent, core_src,
whitelist, blacklist) importer = Importer(self.router, self.parent,
self.router.importer = self.importer core_src, whitelist, blacklist)
self.importer = importer
self.importer._context = self.parent # for fork().
self.router.importer = importer
sys.meta_path.append(self.importer) sys.meta_path.append(self.importer)
def _setup_package(self): def _setup_package(self):
@ -1480,10 +1484,7 @@ class ExternalContext(object):
try: try:
try: try:
self._setup_logging(debug, log_level) self._setup_logging(debug, log_level)
if importer: self._setup_importer(importer, core_src_fd, whitelist, blacklist)
self.importer = importer
else:
self._setup_importer(core_src_fd, whitelist, blacklist)
if setup_package: if setup_package:
self._setup_package() self._setup_package()
self._setup_globals(context_id, parent_ids) self._setup_globals(context_id, parent_ids)

Loading…
Cancel
Save