mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
more intuitive blocking loop
This commit is contained in:
parent
2ae1c16358
commit
b499a5202f
1 changed files with 11 additions and 6 deletions
|
@ -280,13 +280,18 @@ class BackgroundModuleLoader(threading.Thread):
|
|||
|
||||
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):
|
||||
# We assume that module loading is finished when sys.modules doesn't
|
||||
# get longer in 5 consecutive 1ms waiting steps
|
||||
counter = 0
|
||||
last = -1
|
||||
while counter < 5:
|
||||
new = len(sys.modules)
|
||||
if new == last:
|
||||
counter += 1
|
||||
else:
|
||||
last = new
|
||||
counter = 0
|
||||
time.sleep(0.001)
|
||||
last = hist[i % 5] = len(sys.modules)
|
||||
i += 1
|
||||
# now import module properly
|
||||
modname = importlib.util.resolve_name(self.name, self.package)
|
||||
if isinstance(sys.modules[modname], BackgroundModuleProxy):
|
||||
|
|
Loading…
Add table
Reference in a new issue