Skip to content

Commit bb816cc

Browse files
Increase asyncify stack size
Pick the first power of two where we fail with a pystack exhausted error in MicroPython rather than an asyncify-related error.
1 parent 5e619dd commit bb816cc

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

bin/stack-size.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Generates Python files that explore stack size limits
2+
// We hit an asyncify limit here:
3+
// https://github.com/microbit-foundation/micropython-microbit-v2-simulator/issues/105
4+
5+
// At 169 we get pystack exhausted
6+
// With lower powers of 2 for ASYNCIFY_STACK_SIZE we get an asyncify error
7+
// before we exhaust the stack.
8+
const limit = 168;
9+
10+
let code = `
11+
def outer():
12+
i = 0
13+
while True:
14+
print(i)
15+
i += 1
16+
f${limit - 1}()
17+
18+
def f0():
19+
pass
20+
21+
`;
22+
23+
for (let i = limit - 1; i > 0; --i) {
24+
code += `
25+
def f${i}():
26+
f${i - 1}()
27+
28+
`;
29+
}
30+
31+
code += "outer()";
32+
33+
console.log(code);

src/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ COPT += -O3 -DNDEBUG
4444
endif
4545

4646
JSFLAGS += -s ASYNCIFY
47+
# We can hit lower values due to user stack use. See stack-size.mjs.
48+
JSFLAGS += -s ASYNCIFY_STACK_SIZE=262144
4749
JSFLAGS += -s EXIT_RUNTIME
4850
JSFLAGS += -s MODULARIZE=1
4951
JSFLAGS += -s EXPORT_NAME=createModule

0 commit comments

Comments
 (0)