Skip to content

OSError: [Errno 28] 否空间左 on device

错误信息

                [Errno 28] 否空间左 on device
              

快速摘要

操作系统错误 occurred — 特定 subtype (FileNotFoundError, PermissionError, etc.) gives 更多 detail.

为什么发生

  • Disk 完整 (否空间左 on device)

  • Network issues (连接 reset, timeout)

  • Resource 限制 exceeded (也许多打开 files)

  • 无效 OS-level 操作

最小示例

✗ 错误代码
with open('/full_disk/file.txt', 'w') as f:
    f.write('x' * 10**9)  # OSError: No space left on device
✓ 修复代码
try:
    with open('/full_disk/file.txt', 'w') as f:
        f.write('x' * 10**9)
except OSError as e:
    print(f"OS error: {e}")
    # Handle: free space, use different disk, etc.

Catch OSError (or 它的特定 subtype) 到 handle OS-level failures gracefully.

如何诊断

  • 读取 errno and 消息 for 特定 OS 错误

  • 检查系统 resources (disk 空间, file descriptors, memory)

  • 验证 network connectivity for network 操作

如何修复

  • Free 上 disk 空间 or increase quotas

  • 关闭 unused file handles and 连接

  • Handle 特定 OSError subtype appropriately

  • Use try/except OSError for 通用 OS 错误 handling

如何预防

  • Monitor 系统 resources

  • 关闭 files and 连接 promptly (use 上下文 managers)

  • Handle 特定 OSError subtypes separately

相关资源

相关术语

相关课程

← 返回语言