For posterity, as I've spend several days investigating this case, maybe this is going to save somebody else's time.
While running my picoweb server and some mqtt reporting to Thingspeak executed within uasyncio loop on my Wemos D1 mini (ESP8266) after some time I was getting a vague
Code: Select all
ValueError: generator already executing
error message reported for
line of code of the coro definition.
More context:
Error message:
Code: Select all
Traceback (most recent call last):
File "main.py", line 233, in <module>
File "picoweb/__init__.py", line 298, in run
File "uasyncio/core.py", line 154, in run_forever
File "uasyncio/core.py", line 109, in run_forever
File "main.py", line 223, in mem
ValueError: generator already executing
where "main.py", line 223, in mem is:
"main.py", line 233, in is:
As it was happening after dozens of minutes but in the same loop of iteration every time I thought it might be related to memory.
Quick check on gc.mem_free() every loop iteration and it turned out the the heap was going down to as low as ~10kB while the script encountered an interruption with the above error message.
Now, with gc.collect() executed every Thingspeak upload iteration of the loop the script really runs forever
Alternatively you can set the gc.threshold(2000) at the top of your script to make sure gc does the collection with 2kB advance, 2000 is an empirical value confirmed to work for my Wemos D1 mini board.
Anyway, it's interesting why does the uasyncio return this error message and why it fails allocating the memory.
Interestingly, as a follow up, I checked the gc.threshold(-1) to disable allocation threshold and then heap goes to as low as 400 bytes even not causing the issue described above. So, not sure if I nailed this problem right unfortunately.