WebREPL freezes when pasting large code block

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
snake77
Posts: 31
Joined: Thu Jun 24, 2021 11:26 pm

WebREPL freezes when pasting large code block

Post by snake77 » Fri Jul 02, 2021 5:39 pm

I wanted to paste 194 lines of code with the WebREPL but it just freezes my ESP8266. Smaller code blocks with fewer lines work fine. (I haven't tested how much is too much.)

Is that expected behavior?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: WebREPL freezes when pasting large code block

Post by Roberthh » Fri Jul 02, 2021 6:31 pm

The heap of the ESP8266 is rather small. A single source module of 194 lines could be too much. You may have to split that in into smaller pieces. Better upload pre-compiled code using the file transfer method.

snake77
Posts: 31
Joined: Thu Jun 24, 2021 11:26 pm

Re: WebREPL freezes when pasting large code block

Post by snake77 » Fri Jul 02, 2021 8:52 pm

Roberthh wrote:
Fri Jul 02, 2021 6:31 pm
The heap of the ESP8266 is rather small. A single source module of 194 lines could be too much. You may have to split that in into smaller pieces. Better upload pre-compiled code using the file transfer method.
Thanks for the reply. :) However, splitting it up seems tedious. And using the file transfer method is going to write it to file and use up flash cycles, right? Because I'm still changing a lot and would be uploading different version after different version. Hmm...

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: WebREPL freezes when pasting large code block

Post by kevinkk525 » Sat Jul 03, 2021 5:10 am

I wouldn't worry about flash cycles on an esp8266 (and not just because they are dirt cheap). During my development I often end up uploading the whole firmware 20 times a day. For every change I make, I compile and flash a new firmware (which is ~700kB). And none of my devices have had any problems yet.
So I really wouldn't worry about uploading a new file for every change you make (at least not when using littleFS. Don't use fat)
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

snake77
Posts: 31
Joined: Thu Jun 24, 2021 11:26 pm

Re: WebREPL freezes when pasting large code block

Post by snake77 » Sat Jul 03, 2021 11:31 am

kevinkk525 wrote:
Sat Jul 03, 2021 5:10 am
So I really wouldn't worry about uploading a new file for every change you make
Hmm okay. However, I think it would still be more comfortable to be able to paste via WebREPL. 🙈
Roberthh wrote:
Fri Jul 02, 2021 6:31 pm
The heap of the ESP8266 is rather small. A single source module of 194 lines could be too much.
Just tried it via the REPL on the serial console and it works fine there. Does that make a difference regarding the heap?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: WebREPL freezes when pasting large code block

Post by Roberthh » Sat Jul 03, 2021 11:54 am

I expect that webrepl uses memory from the heap. You can check with:

import gc
gc.collect()
gc.mem_free()

from both REPL and WebREPL.
Sometimes it helps doing a import gc;gc.collect() before loading.

kevinkk525
Posts: 969
Joined: Sat Feb 03, 2018 7:02 pm

Re: WebREPL freezes when pasting large code block

Post by kevinkk525 » Sat Jul 03, 2021 12:12 pm

Might also be due to socket operations in webrepl making it slower, more complex and more resource hungry?
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply