Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created October 21, 2022 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JeffersGlass/10adc330d8099fda1ee481bd82bc29c7 to your computer and use it in GitHub Desktop.
Save JeffersGlass/10adc330d8099fda1ee481bd82bc29c7 to your computer and use it in GitHub Desktop.
A demonstration that Pyodide.runPythonAsync() still runs synchronous code synchronously
<!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