Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#11,562 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
43/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
c, embedded-iot, python

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
C
星标
4.6k
派生
1.4k
平均合并
23 小时 40 分钟
30 天内合并 PR
167

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

adafruit/circuitpython 的其他 Issue

查看 adafruit/circuitpython 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。