···11+/**
22+ * This file has been copied from pyodide source and modified to allow
33+ * pyodide to be used in a web worker within this
44+ */
55+66+self.languagePluginUrl = './src';
77+importScripts('./pyodide.js');
88+99+const onmessage = function(e) {
1010+ // eslint-disable-line no-unused-vars
1111+ languagePluginLoader.then(() => {
1212+ // Preloaded packages
1313+ self.pyodide.loadPackage(['matplotlib', 'mne', 'pandas']).then(() => {
1414+ const data = e.data;
1515+ const keys = Object.keys(data);
1616+ for (let key of keys) {
1717+ if (key !== 'python') {
1818+ // Keys other than python must be arguments for the python script.
1919+ // Set them on self, so that `from js import key` works.
2020+ self[key] = data[key];
2121+ }
2222+ }
2323+2424+ self.pyodide
2525+ .runPythonAsync(data.python, () => {})
2626+ .then((results) => {
2727+ self.postMessage({ results });
2828+ })
2929+ .catch((err) => {
3030+ // if you prefer messages with the error
3131+ self.postMessage({ error: err.message });
3232+ // if you prefer onerror events
3333+ // setTimeout(() => { throw err; });
3434+ });
3535+ });
3636+ });
3737+};