micropython / micropython/micropython
Thread on Core 1 on PICO hangs when accessing io
Open
@projectgus is already working on this.
Since Jan 6, 2025.
bug
needs-info
port-rp2
- Dominant language
- C
- Stars
- 22.1k
- Forks
- 9k
- Avg merge
- 6d 4h
- Merged PRs (30d)
- 16
Description
Port, board and/or hardware
Raspberry Pi Pico
MicroPython version
MicroPython v1.23.0 on 2024-06-02; Raspberry Pi Pico with RP2040
Reproduction
import os
import time
import _thread
def core1_thread():
try:
print("entering core1_thread")
text = "some text to log"
# Open log file in append mode
f = open("test.log", "a")
f.write(text)
except OSError as ex:
print(ex)
finally:
f.close()
def create_log():
"""
Check if the log file exists. If the log file does not exist, create the log file and write a header line.
Parameters:
None
Returns:
None
"""
_log_fn = "/test.log"
try:
# File exists
os.stat(_log_fn)
return
except OSError:
idx = _log_fn.rfind("/")
dir = _log_fn[1:idx]
if dir and not dir in os.listdir():
os.mkdir(dir)
# File does not exist
try:
t = f"file {_log_fn} created\n"
with open(_log_fn, "a") as f:
f.write(t)
print(t.rstrip())
except OSError as ex:
raise OSError(f"exception {ex}")
def main():
create_log()
thread = _thread.start_new_thread(core1_thread, ())
if __name__ == "__main__":
main()
time.sleep(1) # if 'mpremote run', allow thread to run before we soft reset
Expected behaviour
Expected to see 'some text to log' in file test.log on pico.
Observed behaviour
After starting the thread it hangs after printing 'entering core1_thread'.
Additional Information
No, I've provided everything above.
Code of Conduct
Yes, I agree
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.