Is a Python event polled or interrupt driven?

Chris Green cl at isbd.net
Thu Oct 12 13:27:31 EDT 2023


Chris Angelico <rosuav at gmail.com> wrote:
> On Fri, 13 Oct 2023 at 01:48, Chris Green via Python-list
> <python-list at python.org> wrote:
> >
> > In the following code is the event polled by the Python process
> > running the code or is there something cleverer going on such that
> > Python sees an interrupt when the input goes high (or low)?
> >
> 
> This isn't something inherent to Python; it's the specific behaviour
> of the library you're using. So I dug through that library a bit, and
> ended up here:
> 
> https://github.com/adafruit/adafruit-beaglebone-io-python/blob/cf306ed7f9f24111d0949dd60ac232e81241bffe/source/event_gpio.c#L753 
> 
> 
> which starts a thread:
> 
> https://github.com/adafruit/adafruit-beaglebone-io-python/blob/cf306ed7f9f24111d0949dd60ac232e81241bffe/source/event_gpio.c#L662 
> 
> 
> which appears to make use of epoll for efficient event handling. Edge
> detection itself seems to be done here:
> 
> https://github.com/adafruit/adafruit-beaglebone-io-python/blob/cf306ed7f9f24111d0949dd60ac232e81241bffe/source/event_gpio.c#L522 
> 
> 
> I don't know enough about the architecture of the BeagleBone to be
> certain, but my reading of it is that most of the work of edge
> detection is done by the OS kernel, which then sends the Adafruit
> handler a notification via a file descriptor. The secondary thread
> waits for those messages (which can be done very efficiently), and in
> turn calls the Python callbacks.
> 
> In other words, the "something cleverer" is all inside the OS kernel,
> and yes, in effect, it's an interrupt.
> 
Wow! Thanks for doing all that research.  It sounds as if it may be
more efficient than I thought so may be fast enough.  I guess I'll
just have to try some actual code (and hardware) and see how it goes.

Thanks again!

-- 
Chris Green
·


More information about the Python-list mailing list