예제 #1
0
파일: listener.py 프로젝트: osneven/usbauth
    def listen(self):

        # Initialize pyudev monitor
        ctx = Context()
        mon = Monitor.from_netlink(ctx)
        mon.start()

        # Start listening and send all new connections to another thread
        LOGGER.log("Listening for USB devices")
        try:
            for dev in iter(mon.poll, None):
                connection_thread = Thread(target=Listener.connection,
                                           args=[self, dev])
                connection_thread.daemon = True
                connection_thread.start()
        except KeyboardInterrupt:
            LOGGER.log("Exited by user!")
            Paths.delete_tmp_dir()
            exit()