seems to work

This commit is contained in:
Anthony Scopatz 2016-06-26 14:41:53 -04:00
parent 115a095647
commit 502f1a6627
5 changed files with 54 additions and 1 deletions

View file

@ -150,7 +150,7 @@ class _LazyModule(_ModuleType):
pkg = dct['pkg']
asname = dct['asname']
if asname is None:
glbs[pkg] = _modules[pkg]
glbs[pkg] = m = _modules[pkg]
else:
glbs[asname] = m
dct['loaded'] = True

View file

@ -9,6 +9,8 @@ else:
import sys as _sys
try:
from xonsh import __amalgam__
bg_pkg_resources = __amalgam__
_sys.modules['xonsh.bg_pkg_resources'] = __amalgam__
completer = __amalgam__
_sys.modules['xonsh.completer'] = __amalgam__
lazyasd = __amalgam__

44
xonsh/bg_pkg_resources.py Normal file
View file

@ -0,0 +1,44 @@
"""Background thread loader for pkg_resources."""
import os
import sys
import time
import builtins
import threading
import importlib
class PkgResourcesLoader(threading.Thread):
"""Thread to load the pkg_resources module."""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.daemon = True
self.start()
def run(self):
# wait for other modules to stop being imported
i = 0
last = -6
hist = [-5, -4, -3, -2, -1]
while not all(last == x for x in hist):
time.sleep(0.001)
last = hist[i%5] = len(sys.modules)
i += 1
# now import pkg_resources properly
if sys.modules['pkg_resources'] is None:
del sys.modules['pkg_resources']
pr = importlib.import_module('pkg_resources')
if 'pygments.plugin' in sys.modules:
sys.modules['pygments.plugin'].pkg_resources = pr
def load_pkg_resources_in_background():
"""Entry point for loading pkg_resources module in background."""
if 'pkg_resources' in sys.modules:
return
env = getattr(builtins, '__xonsh_env__', os.environ)
if env.get('XONSH_DEBUG', None):
import pkg_resources
return
sys.modules['pkg_resources'] = None
PkgResourcesLoader()

View file

@ -0,0 +1,3 @@
# must come before ptk / pygments imports
from xonsh.bg_pkg_resources import load_pkg_resources_in_background
load_pkg_resources_in_background()

View file

@ -9,6 +9,10 @@ from warnings import warn
from collections import ChainMap
from collections.abc import MutableMapping
# must come before pygments imports
from xonsh.bg_pkg_resources import load_pkg_resources_in_background
load_pkg_resources_in_background()
from pygments.lexer import inherit, bygroups, using, this
from pygments.lexers.shell import BashLexer
from pygments.lexers.agile import PythonLexer