USB device status update inside container

66 Views Asked by At

import usb
import pyudev

def detect_device():
    dev = usb.core.find(idVendor=VENDOR_ID, idProduct=PRODUCT_ID)
    if dev is None:
        print("No device found")
        return False
    else:
        print("USB device found")
        return True

while True:
    print(detect_device())

I am trying to detect whether usb device is inserted into the device or not inside the container.I am running a python script to do this.But inside the container when I run the code, the status of the device doesn't get updated during run time.Even if I remove the device status remains as inserted.Once I stop the code and rerun, status get updated.Though the code works as expected outside the container but only inside the container status update happens only in the beginning of the execution.

I have already tried to clear the usb status after checking,garbage collectors,reimporting but no luck.

Above is the sample code.

0

There are 0 best solutions below