Python 如果没有监视器插入PI,psutil将无法运行

Python 如果没有监视器插入PI,psutil将无法运行,python,raspberry-pi4,psutil,Python,Raspberry Pi4,Psutil,我有一个raspberry pi,它在重新启动时运行pyudev和psutil脚本来查找可移动存储设备。如果插入了监视器,脚本运行得非常好。但只要我拔下屏幕并重新启动PI,它就不会加载psutil。我甚至找不到错误是什么,因为错误输出是: >@>@>@>@>@>@>@>@>@>@>@ 这是我的剧本: def checkstorage(): context = pyudev.Context() removable

我有一个raspberry pi,它在重新启动时运行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安装到我选择的特定路径来修复此问题