if we read this, We can detect USB connected/disconnected using pyUdev
- https://pyudev.readthedocs.io/en/latest/guide.html#asynchronous-monitoring
using this sample, When USB = connect/disable timing, the callback ( usbDeviceEventHandler ) is called. this is good.
self.observer = pyudev.MonitorObserver(monitor, usbDeviceEventHandler)
self.observer.start()
but there is problem…
async def usbDeviceEventHandler
....
To use “asynchronous” callback is not possible..
it not work correctly…
Do you have any idea ?
1
The handler itself must be a sync function, but it can create an asyncio Task:
def usbDeviceEventHandler():
async def aHandler():
# do async things here, concurrently with other Tasks
asyncio.create_task(aHandler())