Merge pull request #272 from mdboom/package-loading-race-condition

Fix package loading race condition
This commit is contained in:
Roman Yurchak 2018-12-10 22:25:06 +01:00 committed by GitHub
commit 1984cc5688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 2 deletions

View File

@ -148,8 +148,14 @@ var languagePluginLoader = new Promise((resolve, reject) => {
messageCallback(`Loading ${packageList}`); messageCallback(`Loading ${packageList}`);
} }
window.pyodide._module.monitorRunDependencies = (n) => { // monitorRunDependencies is called at the beginning and the end of each
if (n === 0) { // package being loaded. We know we are done when it has been called
// exactly "toLoad * 2" times.
var packageCounter = Object.keys(toLoad).length * 2;
window.pyodide._module.monitorRunDependencies = () => {
packageCounter--;
if (packageCounter === 0) {
for (let package in toLoad) { for (let package in toLoad) {
window.pyodide.loadedPackages[package] = toLoad[package]; window.pyodide.loadedPackages[package] = toLoad[package];
} }