From b6d06454b24502281c9e41bdb66ecdb631e68b06 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 6 Dec 2018 18:19:08 -0500 Subject: [PATCH 1/3] Fix package loading race condition --- src/pyodide.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pyodide.js b/src/pyodide.js index 56f5649a7..9f2189ca4 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -148,8 +148,11 @@ var languagePluginLoader = new Promise((resolve, reject) => { messageCallback(`Loading ${packageList}`); } + var packageCounter = Object.keys(toLoad).length * 2; + window.pyodide._module.monitorRunDependencies = (n) => { - if (n === 0) { + packageCounter--; + if (packageCounter === 0) { for (let package in toLoad) { window.pyodide.loadedPackages[package] = toLoad[package]; } From 19475e1ab58423ed40f34fe011bc543e5aa65d60 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 6 Dec 2018 18:25:10 -0500 Subject: [PATCH 2/3] Add comment --- src/pyodide.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/pyodide.js b/src/pyodide.js index 9f2189ca4..03553924c 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -148,6 +148,9 @@ var languagePluginLoader = new Promise((resolve, reject) => { messageCallback(`Loading ${packageList}`); } + // monitorRunDependencies is called at the beginning and the end of each + // 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 = (n) => { From 5484bc73c8428ad70d3421ad3f809f9d8861712b Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 6 Dec 2018 18:51:36 -0500 Subject: [PATCH 3/3] Remove unnecessary argument --- src/pyodide.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pyodide.js b/src/pyodide.js index 03553924c..895fdd133 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -153,7 +153,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { // exactly "toLoad * 2" times. var packageCounter = Object.keys(toLoad).length * 2; - window.pyodide._module.monitorRunDependencies = (n) => { + window.pyodide._module.monitorRunDependencies = () => { packageCounter--; if (packageCounter === 0) { for (let package in toLoad) {