Why would file.close() freeze/crash pico using micropython? #14249
Replies: 4 comments 10 replies
-
Is it possible you have written files so many times, the built-in flash is dying? I have a PicoW I was using as a data logger, which ran perfectly for 6 months, and then started freezing up frequently. It would record data, and once a day it would be downloaded and erased. The write count on each block was probably a few hundred. I'm pretty sure I have killed the flash. |
Beta Was this translation helpful? Give feedback.
-
stack: 1796 out of 7936 This is my micropython.mem_info() print right before the freeze happens on file close. Is it an issue of something needing more than the max free block size? A fragmentation issue? |
Beta Was this translation helpful? Give feedback.
-
Update: The issue is fixed by eliminating my threaded portion of the code altogether. I understand that _thread doesn't have the best track record with micropython, but I still am unsure as to why it would affect file system/flash at all if it is not using it or sharing any variables? |
Beta Was this translation helpful? Give feedback.
-
Re threading on RP2 you might want to read this doc. tl;dr It needs using with great care. |
Beta Was this translation helpful? Give feedback.
-
Hello,
I have had a freezing issue for a while now and I have found it to be caused by file.close() function when writing to a .txt file in my program. It seems to work sometimes but a good 33% of the time it will hang itself up on that portion specifically. The file is only around 25 lines and it is just storing 25 different numbers for me, so it is not large at all. I have tried using the 'with open' method with the same result. Is there something I need to be aware of when trying to close the file? Perhaps give it more time after the last item is written to close it? Right now it writes all items with a 100ms sleep in between each and a 100ms sleep between the last write and the close() call. This seems to only happen with the pico, not any stm I have tried. Any help is appreciated, thanks.
Edit:
I am using a W5100S pico for this and have tried v1.19 to v1.22 micropython and the issue persists.
Beta Was this translation helpful? Give feedback.
All reactions