vpelletier / python-libusb1

Python ctype-based wrapper around libusb1
GNU Lesser General Public License v2.1
168 stars 65 forks source link

Event handler context #89

Closed ValaJeyhani closed 8 months ago

ValaJeyhani commented 11 months ago

Thanks for the great library. The asynchronous support is vital for our application and your library handles it beautifully!

I have a question though. In what context are the event handler callbacks called? Is it a different thread? Should I be worried about issues related to concurrent execution?

Cheers, Vala

ValaJeyhani commented 11 months ago

I guess the answer is any context that the handleEvents* functions are called in. Is that correct? Am I right that calling the handleEvents* is necessary to process events?

vpelletier commented 11 months ago

Thanks for the kind words.

I guess the answer is any context that the handleEvents functions are called in. Is that correct? Am I right that calling the handleEvents is necessary to process events?

Correct and correct. I try to follow libusb1's design principles, and one of those is to not create threads behind the back of the application.

For completeness, there is nowadays one exception on libusb1's side about hotplug even handling, where the library's internal state is updated using a thread - but this should not call into any application code, not even callbacks - so this should be invisible to the python interpreter.

ValaJeyhani commented 8 months ago

Thanks @vpelletier for the clarification!