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)?
On Fri, 13 Oct 2023 at 01:48, Chris Green via Python-list <python-list@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.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 66:34:10 |
Calls: | 6,712 |
Files: | 12,244 |
Messages: | 5,356,312 |