mirror of
https://github.com/TomHodson/tomhodson.github.com.git
synced 2025-06-26 10:01:18 +02:00
Fix long running processes
This commit is contained in:
parent
a234320e0a
commit
aa2e97cea2
@ -79,13 +79,6 @@ mp.runPython("import fonts; print(fonts.gunship30)")
|
|||||||
|
|
||||||
Note that I've got access to my compiled in code here.
|
Note that I've got access to my compiled in code here.
|
||||||
|
|
||||||
<section class = "micropython-simulator">
|
|
||||||
<div id="editor"></div>
|
|
||||||
<button id=run title="Run code (Ctrl-Enter)" aria-title="Run code (Ctrl-Enter)">Run</button>
|
|
||||||
<canvas height="240" width="240" class = screen></canvas>
|
|
||||||
<pre id="micropython-stdout"></pre>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<script src="{{page.assets}}/cm6.bundle.min.js"></script>
|
<script src="{{page.assets}}/cm6.bundle.min.js"></script>
|
||||||
<script src="{{page.assets}}/simulator.js" type = "module"></script>
|
<script src="{{page.assets}}/simulator.js" type = "module"></script>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
import asyncio
|
||||||
import gc
|
import gc
|
||||||
import struct
|
import struct
|
||||||
import time
|
|
||||||
from array import array
|
from array import array
|
||||||
|
|
||||||
import console
|
import console
|
||||||
@ -102,7 +102,10 @@ while True:
|
|||||||
)
|
)
|
||||||
|
|
||||||
display.draw(buf)
|
display.draw(buf)
|
||||||
# The 'await' is necessary here to yield back to the JS event loop
|
|
||||||
# I tried to figure out how to hide this inside the JS implementation of sleep but
|
# Note: Because of the way the webassembly port works, this code is actually running like an asyncio thread
|
||||||
# couldn't make it work.
|
# This call to asyncio.sleep yeilds back to the JS event loop and gives the browser a chance to update the display.
|
||||||
await time.sleep(0.2)
|
# This is not needed on a real device.
|
||||||
|
# There is way to make it so that a bare time.sleep() will work but it requires emcripten's ASYNCIFY feature
|
||||||
|
# Which apparently kills performance. See https://github.com/tomhodson/micropython/commit/2fa6373d226b65f977486ecda32b8786cd1dceed
|
||||||
|
await asyncio.sleep(0.2)
|
||||||
|
File diff suppressed because one or more lines are too long
Binary file not shown.
@ -6,9 +6,6 @@ class USBCPowerSupplySimulator extends HTMLElement {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mp.registerJsModule("console", { log: (s) => console.log(s) });
|
mp.registerJsModule("console", { log: (s) => console.log(s) });
|
||||||
mp.registerJsModule("time", {
|
|
||||||
sleep: async (s) => await new Promise((r) => setTimeout(r, s * 1000)),
|
|
||||||
});
|
|
||||||
mp.registerJsModule("display", {
|
mp.registerJsModule("display", {
|
||||||
draw: (buf) => {
|
draw: (buf) => {
|
||||||
let bytes = [...buf].flatMap((x) => [x, x, x, 255]);
|
let bytes = [...buf].flatMap((x) => [x, x, x, 255]);
|
||||||
@ -45,10 +42,7 @@ class USBCPowerSupplySimulator extends HTMLElement {
|
|||||||
mp_console.scrollTo(0, mp_console.scrollHeight);
|
mp_console.scrollTo(0, mp_console.scrollHeight);
|
||||||
};
|
};
|
||||||
|
|
||||||
const [mp, view] = await Promise.all([
|
const view = await this.init_editor();
|
||||||
this.init_mp(ctx, stdoutWriter),
|
|
||||||
this.init_editor(),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const runPython = async () => {
|
const runPython = async () => {
|
||||||
mp_console.innerText = "";
|
mp_console.innerText = "";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user