admirez
V2EX  ›  Codex

Codex 运行 Python 测试后,仓库根目录出现大量 4 字节随机文件

  •  
  •   admirez · Apr 17 · 1017 views
    This topic created in 34 days ago, the information mentioned may be changed or developed.
    我实在是不知道如何避免这个问题,出现多次了。

    下面的内容是我让 codex 自己总结的:

    环境是 Windows 11 + PowerShell 。Codex 为了验证一个很小的 merge_stocks.py 逻辑修改,新增了 unittest ,测试里用了 tempfile.TemporaryDirectory()。

    运行:

    python -B -m unittest discover -s test -p "test_*.py"

    时,Python 的 tempfile 会调用 gettempdir() 探测可用临时目录。探测过程会在候选目录里创建一个随机文件名的小文件,通常写
    入 4 字节内容,然后马上删除。

    当前环境下系统临时目录不可用或权限异常,tempfile 继续尝试其他候选目录,最后尝试到了仓库根目录。由于创建成功但删除失
    败,就在仓库根目录留下了一批 8 位随机文件名、大小 4 字节的小文件。

    这些文件不是业务代码生成的,而是 Python tempfile 在探测临时目录时留下的临时探针文件。
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   958 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 20:16 · PVG 04:16 · LAX 13:16 · JFK 16:16
    ♥ Do have faith in what you're doing.