(self)
Close this handle. If not called explicitely, will be called by
        destructor.

        This method cancels any in-flight transfer when it is called. As
        cancellation is not immediate, this method needs to let libusb handle
        events until transfers are actually cancelled.
        In multi-threaded programs, this can lead to stalls. To avoid this,
        do not close nor let GC collect a USBDeviceHandle which has in-flight
        transfers.
Close this handle. If not called explicitely, will be called by
        destructor.
Close this handle . If not called explicitely will be called by destructor .
def close(self):
        """
        Close this handle. If not called explicitely, will be called by
        destructor.

        This method cancels any in-flight transfer when it is called. As
        cancellation is not immediate, this method needs to let libusb handle
        events until transfers are actually cancelled.
        In multi-threaded programs, this can lead to stalls. To avoid this,
        do not close nor let GC collect a USBDeviceHandle which has in-flight
        transfers.
        """
        handle = self.__handle
        if handle is not None:
            # Build a strong set from weak self.__transfer_set so we can doom
            # and close all contained transfers.
            # Because of backward compatibility, self.__transfer_set might be a
            # wrapper around WeakKeyDictionary. As it might be modified by gc,
            # we must pop until there is not key left instead of iterating over
            # it.
            weak_transfer_set = self.__transfer_set
            transfer_set = self.__set()
            while True:
                try:
                    transfer = weak_transfer_set.pop()
                except KeyError:
                    break
                transfer_set.add(transfer)
                transfer.doom()
            inflight = self.__inflight
            for transfer in inflight:
                try:
                    transfer.cancel()
                except self.__USBError:
                    if sys.exc_info()[1].value != \
                            self.__LIBUSB_ERROR_NOT_FOUND:
                        raise
            while inflight:
                self.__context.handleEvents()
            for transfer in transfer_set:
                transfer.close()
            self.__libusb_close(handle)
            self.__handle = None
def close ( self ) : handle = self . __handle if handle is not None : # Build a strong set from weak self.__transfer_set so we can doom # and close all contained transfers. # Because of backward compatibility, self.__transfer_set might be a # wrapper around WeakKeyDictionary. As it might be modified by gc, # we must pop until there is not key left instead of iterating over # it. weak_transfer_set = self . __transfer_set transfer_set = self . __set ( ) while True : try : transfer = weak_transfer_set . pop ( ) except KeyError : break transfer_set . add ( transfer ) transfer . doom ( ) inflight = self . __inflight for transfer in inflight : try : transfer . cancel ( ) except self . __USBError : if sys . exc_info ( ) [ 1 ] . value != self . __LIBUSB_ERROR_NOT_FOUND : raise while inflight : self . __context . handleEvents ( ) for transfer in transfer_set : transfer . close ( ) self . __libusb_close ( handle ) self . __handle = None