python-libusb1 icon indicating copy to clipboard operation
python-libusb1 copied to clipboard

Feature request: USBContext.handleEventsCompleted()

Open multiplemonomials opened this issue 1 year ago • 3 comments

It seems like, looking at the libusb async API docs, this function is the best way to solve the problem of "handle events only until a specific transfer is done." However, it doesn't currently exist in python-libusb1 and is marked as TODO. I'd love it if you could add this function, especially if it could get a Python wrapper that allows waiting for a list of transfers to complete.

multiplemonomials avatar Jan 21 '24 02:01 multiplemonomials

It seems like, looking at the libusb async API docs, this function is the best way to solve the problem of "handle events only until a specific transfer is done."

This would be "Multi-threaded applications and asynchronous I/O", and especially the "libusb_handle_events() from multiple threads" section.

Would it make sense to have a USB event handling thread which would just call handleEvents in a loop, and, instead of calling an event handler function in the code waiting for a specific transfer to complete, wait on a mutex which would get set in the completion callback ?

vpelletier avatar Jan 22 '24 01:01 vpelletier

That would be pretty cool, especially if it could provide some sort of "wait for this list of USBTransfers to complete" functionality

multiplemonomials avatar Jan 23 '24 07:01 multiplemonomials

Sorry, I was unclear: what I was suggesting is something which can be done outsite of python-libusb1, in your implementation of the transfer callback. I would rather keep as much of threading, locking and global tracking outside of python-libusb1 as possible.

vpelletier avatar Mar 04 '24 14:03 vpelletier