Skip to content

Commit

Permalink
Increase asyncify stack size (#106)
Browse files Browse the repository at this point in the history
Pick the first power of two where we fail with a pystack exhausted
error in MicroPython rather than an asyncify-related error.

Add an example to the demo that finds the max stack size.
  • Loading branch information
microbit-matt-hillsdon authored Sep 26, 2023
1 parent 5e619dd commit 009abf4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ COPT += -O3 -DNDEBUG
endif

JSFLAGS += -s ASYNCIFY
# We can hit lower values due to user stack use. See stack_size.py example.
JSFLAGS += -s ASYNCIFY_STACK_SIZE=262144
JSFLAGS += -s EXIT_RUNTIME
JSFLAGS += -s MODULARIZE=1
JSFLAGS += -s EXPORT_NAME=createModule
Expand Down
1 change: 1 addition & 0 deletions src/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ <h1>MicroPython-micro:bit simulator example embedding</h1>
</option>
<option value="sound_effects_user">Sound effects (user)</option>
<option value="speech">Speech</option>
<option value="stack_size">Stack size</option>
<option value="volume">Volume</option>
</select>
<textarea
Expand Down
10 changes: 10 additions & 0 deletions src/examples/stack_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def g():
global depth
depth += 1
g()
depth = 0
try:
g()
except RuntimeError:
pass
print('maximum recursion depth g():', depth)

0 comments on commit 009abf4

Please sign in to comment.