Pop-Up Thingie

>>> Magnum BBS <<<
  • Home
  • Forum
  • Files
  • Log in

  1. Forum
  2. Usenet
  3. COMP.LANG.PYTHON
  • Is a Python event polled or interrupt driven?

    From Chris Green@21:1/5 to All on Thu Oct 12 10:21:07 2023
    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)?



    import Adafruit_BBIO.GPIO as GPIO

    Pin = "P8_8"
    GPIO.setup(Pin, GPIO.IN) # set GPIO25 as input (button)

    def my_callback(channel):
    if GPIO.input(Pin):
    print "Rising edge detected on 25"
    else: # if port 25 != 1
    print "Falling edge detected on 25"

    GPIO.add_event_detect(Pin, GPIO.BOTH, my_callback, 1)


    --
    Chris Green
    ·

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Angelico@21:1/5 to python-list@python.org on Fri Oct 13 02:07:14 2023
    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.

    ChrisA

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Chris Green@21:1/5 to Chris Angelico on Thu Oct 12 18:27:31 2023
    Chris Angelico <rosuav@gmail.com> wrote:
    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.

    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
    ·

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • Who's Online

  • Recent Visitors

    • Gretchiie
      Tue Sep 16 05:20:21 2025
      from Derry, Nh via Telnet
    • Ginger1
      Mon Sep 15 19:33:54 2025
      from London via SSH
    • Bob Worm
      Mon Sep 15 15:42:34 2025
      from Wales, Uk via Telnet
    • Gretchiie
      Mon Sep 15 05:16:29 2025
      from Derry, Nh via Telnet
    • Fred Blogs
      Mon Sep 15 00:03:12 2025
      from Uk via SSH
    • Plume
      Sun Sep 14 09:34:52 2025
      from Uk via Raw
    • Gretchiie
      Sun Sep 14 06:07:30 2025
      from Derry, Nh via Telnet
    • Thlc
      Sat Sep 13 17:11:34 2025
      from Rognac, France via Telnet
  • System Info

    Sysop: Keyop
    Location: Huddersfield, West Yorkshire, UK
    Users: 546
    Nodes: 16 (2 / 14)
    Uptime: 26:03:18
    Calls: 10,390
    Calls today: 1
    Files: 14,064
    Messages: 6,417,039

© >>> Magnum BBS <<<, 2025