如果我们读到这篇文章,我们可以使用 pyUdev 检测 USB 连接/断开
使用此示例,当 USB = 连接/禁用计时时,调用回调 ( usbDeviceEventHandler )。这很好。
self.observer = pyudev.MonitorObserver(monitor, usbDeviceEventHandler)
self.observer.start()
但是有问题...
async def usbDeviceEventHandler
....
使用“异步”回调是不可能的。 它无法正常工作...
你有什么想法吗?
处理程序本身必须是同步函数,但它可以创建异步任务:
def usbDeviceEventHandler():
async def aHandler():
# do async things here, concurrently with other Tasks
asyncio.create_task(aHandler())