python - 如果没有监视器插入 PI,psutil 将无法运行
问题描述
我有一个树莓派,它在重新启动时会运行 pyudev 和 psutil 脚本来查找可移动存储设备。如果插入了监视器,该脚本运行得非常好。但是一旦我拔下屏幕并重新启动 PI,它就不会加载 psutil。我什至找不到错误是什么,因为错误输出是:
>@>@>@>@>@>@>@>@>@>@>@
这是我的脚本:
def checkstorage():
context = pyudev.Context()
removable = [device for device in context.list_devices(subsystem='block', DEVTYPE='disk') if device.attributes.asstring('removable') == "1"]
for device in removable:
partitions = [device.device_node for device in context.list_devices(subsystem='block', DEVTYPE='partition', parent=device)]
print("All removable partitions: {}".format(", ".join(partitions)))
print("Mounted removable partitions:")
for p in psutil.disk_partitions():
if p.device in partitions:
print(" {}: {}".format(p.device, p.mountpoint))
if p.device == "/dev/sda1":
path = p.mountpoint
else:
path = 0
return path, True
它失败了:
for p in psutil.disk_partitions()
如果没有插HDMI屏
解决方案
问题是,一旦显示器被拔掉,PI 就像一个无头 PI。该实习生导致 psutil 失败,因为没有与 USB 关联的分区。我通过手动将 USB 安装到我选择的特定路径来解决此问题。
推荐阅读
- sorting - 詹金斯排序方法的行为不像预期的那样
- php - 为什么 PHP sleep() 会阻止 Postgresql 查询?
- sql - 使用group by后如何将结果集组合成一行
- neo4j - 如何在neo4j中将时间戳转换为日期
- java - 无法从浏览器访问我的 springboot 应用程序
- php - PHP没有使用准备好的语句从mysql中选择任何值
- javascript - 我正在做一个切换,我想在切换功能触发时更改 div 的背景颜色变化
- reactjs - 想要在特定条件下显示标签
- gcc - Linux 的 Windows 子系统中的 GNU 汇编程序失败
- sql - 在 SQL 中查找每个部门员工的最高薪水