Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Unflushed writes to an open SD card file are lost when the VM stops

Đang mở
#11,562 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
43/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, embedded-iot, python
Lĩnh vực
backend, embedded-iot

Hướng nghiên cứu

Start by tracing stop_mp(), gc_deinit(), and gc_sweep_all() alongside reset_port(); the issue identifies these as the shutdown path and the point where SPI may already be reset. Investigate how open files are closed and how finalizer order affects the SDCard object. Done means stopping or finishing with an open file preserves writes and does not print the empty OSError; the payload names no test file.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug sdcardio storage

Claude wrote this:

CircuitPython version and board name
Adafruit CircuitPython 11.0.0-alpha.1-69-g03db5f8ca4 on 2026-10-11; Adafruit PyPortal with samd51j20
Code
import board, sdcardio, storage, time

sdcard = sdcardio.SDCard(board.SPI(), board.SD_CS)
storage.mount(storage.VfsFat(sdcard), "/sd")

log = open("/sd/LOG.TXT", "a")
i = 0
while True:
    log.write("line %d\n" % i)
    i += 1
    if i % 100 == 0:
        log.flush()
    time.sleep(0.03)
Behavior

When code.py is stopped by auto-reload, or finishes with the file still open:

  • OSError: with no message is printed after "Code stopped by auto-reload" or "Code done running."
  • Lines written since the last flush() are lost. A newly created file that was never flushed does not appear on the card at all.
Description

The file is only closed when its finaliser runs in gc_sweep_all(), from gc_deinit() in stop_mp(). By then reset_port() has already reset the SPI bus, and the SDCard object may have been finalised first, since sweep order is arbitrary. The close() in the finaliser fails, and mp_call_function_1_protected() prints the exception.

Split out from #9138, whose hard hang no longer reproduces.

Ngôn ngữ chính
C
Star
4.6k
Fork
1.4k
Merge trung bình
1 ngày 2 giờ
Pull request đã merge (30 ngày)
174

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của adafruit/circuitpython

Tất cả issue của adafruit/circuitpython

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.