Added "globals" as a 2nd param to runPythonAsync (#1914)

This commit is contained in:
Cyrille Bogaert 2021-10-28 04:18:58 +02:00 committed by GitHub
parent 966714a48d
commit 4042db2615
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -176,11 +176,14 @@ export async function loadPackagesFromImports(
* console.log(result); // 79
*
* @param {string} code Python code to evaluate
* @param {PyProxy} globals An optional Python dictionary to use as the globals.
* Defaults to :any:`pyodide.globals`. Uses the Python API
* :any:`pyodide.eval_code_async` to evaluate the code.
* @returns {Py2JsResult} The result of the Python code translated to JavaScript.
* @async
*/
export async function runPythonAsync(code) {
let coroutine = Module.pyodide_py.eval_code_async(code, Module.globals);
export async function runPythonAsync(code, globals = Module.globals) {
let coroutine = Module.pyodide_py.eval_code_async(code, globals);
try {
return await coroutine;
} finally {