Created
October 21, 2022 16:59
-
-
Save JeffersGlass/10adc330d8099fda1ee481bd82bc29c7 to your computer and use it in GitHub Desktop.
A demonstration that Pyodide.runPythonAsync() still runs synchronous code synchronously
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width,initial-scale=1" /> | |
<link rel="icon" type="image/png" href="favicon.png" /> | |
<link rel="stylesheet" href="https://pyscript.net/releases/2022.09.1/pyscript.css" /> | |
<script defer src="https://pyscript.net/releases/2022.09.1/pyscript.js"></script> | |
</head> | |
<body> | |
<button onclick="runPythonTwice()">Click to Run Python</button> | |
<script> | |
async function runPython(id) { | |
console.log(`About to run synchronous code ${id}`) | |
await pyscript.runtime.interpreter.runPythonAsync(`for _ in range(10_000_000):\n x=1\nconsole.log("${id} 1")`) | |
await pyscript.runtime.interpreter.runPythonAsync(`for _ in range(10_000_000):\n x=1\nconsole.log("${id} 2")`) | |
console.log(`Done running ${id}`) | |
} | |
function runPythonTwice(){ | |
runPython('A') | |
runPython('B') | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just stumbled here from Google. This example is flawed, you
await
both invocations in sequence. Instead try: