Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

You are an insult to my intelligence! I demand that you log off immediately.


devel / comp.lang.python / Re: Is a Python event polled or interrupt driven?

SubjectAuthor
* Is a Python event polled or interrupt driven?Chris Green
`* Re: Is a Python event polled or interrupt driven?Chris Angelico
 `- Re: Is a Python event polled or interrupt driven?Chris Green

1
Is a Python event polled or interrupt driven?

<3dqkvj-vblf3.ln1@esprimo.zbmc.eu>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24120&group=comp.lang.python#24120

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: cl...@isbd.net (Chris Green)
Newsgroups: comp.lang.python
Subject: Is a Python event polled or interrupt driven?
Date: Thu, 12 Oct 2023 10:21:07 +0100
Lines: 23
Message-ID: <3dqkvj-vblf3.ln1@esprimo.zbmc.eu>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net uMrpQT9HLleWpq5sMpoQ3gM/eJm+zvlawABKyacBCFWpdYu8I=
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:CBDPI7PoFzNjUcpKU4J0v8eN4o4= sha256:oqEdGgY/BThR8PsdeFuDuUOsGQmTpgI8f2StaE6Zh38=
User-Agent: tin/2.6.2-20220130 ("Convalmore") (Linux/5.15.0-79-generic (x86_64))
 by: Chris Green - Thu, 12 Oct 2023 09:21 UTC

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
·

Re: Is a Python event polled or interrupt driven?

<mailman.4.1697123248.21446.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24121&group=comp.lang.python#24121

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Is a Python event polled or interrupt driven?
Date: Fri, 13 Oct 2023 02:07:14 +1100
Lines: 34
Message-ID: <mailman.4.1697123248.21446.python-list@python.org>
References: <3dqkvj-vblf3.ln1@esprimo.zbmc.eu>
<CAPTjJmp2te2wVkNjwu1EWCXZ2a0ppSgjK2axYTD5tydHE4yvzA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de 31M/xTm79Vqlcedps2QnoQokvMxHh7oTRZ7p/9UnJrjw==
Cancel-Lock: sha1:R+ebI9h9hUi1EC12jBoS7NAbuzw= sha256:hHb7fpllrDH2jQ+cII1Xu90DsNuRJKe+1Z1sdIHEhOo=
Return-Path: <rosuav@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=OgAY27Ni;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url-ip:140.82/16': 0.03;
'(which': 0.04; 'subject:event': 0.04; 'thread': 0.05; '2023':
0.07; 'architecture': 0.07; 'ended': 0.09; 'thread:': 0.09;
'subject:Python': 0.12; 'url:github': 0.14; 'url-ip:140/8': 0.15;
'adafruit': 0.16; 'behaviour': 0.16; 'chrisa': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'python;': 0.16; 'sees': 0.16; 'using.': 0.16; 'wrote:': 0.16;
'python': 0.16; 'calls': 0.19; 'to:addr:python-list': 0.20;
'input': 0.21; 'fri,': 0.22; 'code': 0.23; 'seems': 0.26;
'library': 0.26; "isn't": 0.27; 'done': 0.28; 'chris': 0.28;
'goes': 0.28; 'python-list': 0.32; 'secondary': 0.32; 'words,':
0.32; 'message-id:@mail.gmail.com': 0.32; 'but': 0.32; 'there':
0.33; 'header:In-Reply-To:1': 0.34; 'received:google.com': 0.34;
'running': 0.34; 'yes,': 0.35; 'following': 0.35;
'from:addr:gmail.com': 0.35; 'those': 0.36; "it's": 0.37; 'file':
0.38; 'enough': 0.39; 'use': 0.39; 'appears': 0.40; 'something':
0.40; 'event': 0.40; 'detection': 0.76; 'effect,': 0.84;
'inherent': 0.84; 'url:source': 0.89; 'green': 0.96
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1697123246; x=1697728046; darn=python.org;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:from:to:cc:subject:date:message-id:reply-to;
bh=0KgqLD6JIJ4QaKEBVdQr5li2tEWHG67DqzRW7beRT7g=;
b=OgAY27Ni57QRoYjbtFPZCPIYsk1gmBigXnzY8yA7NsTbLgJASa3QmX/IuqefpjIdVQ
Hm65s2qKoFfRMbiiOkEL2iqNN5nifkHIiPDlSMOW1Xhx8ITPwWpa/nKQw0jYnJ4HKLqj
GoPXOy4Svy/mmw4b1N3GibM/0P2dxtU4zUJ9LmJXX7yfUERBkZOoxBJlVCHkLK5Y4bqk
7pCGFhn0yWwdUSpiXnEa6xxdPYxxbcsOm/QA+Gu5SCiXsTBk2QAosWdpDoct3sA/EhV9
lYLH4HPR/aiN0vhGpQ72srfVDSQQKZXtIFMcDy7DGGe59Y7eHG06ZdxvnQOzMHakgQ6+
Z4HA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1697123246; x=1697728046;
h=to:subject:message-id:date:from:in-reply-to:references:mime-version
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
bh=0KgqLD6JIJ4QaKEBVdQr5li2tEWHG67DqzRW7beRT7g=;
b=qlctd2TfMxE7eMR6ya1iiJHxW0CqNpfVVzDbslCVVN/dvuWcgU87m00COiv3nUZNyP
6Z8Wn2LR+3KPVuaGWEilj9F2hfxrW6e5xRWgYADZvxJi7TBweQyy3hgI/rpSmxe14cIQ
eIOhCIrnR2W9vR9PBBCANJKj9ScNMw7VA9WypwMxZTmldsaI+FIV+XiB4zORSxy0nVUF
DjQMNK7c/27OaBcdp/gNzaoFs1HefPofd6LMi7SCoft3dYqcNXF9w7uWRO++j13ApkLr
t/9TLKvCanv3ecSCXjVdCG4m+iLKi8R5oOYPqfGfVMRZ57mYd2i70JRiykG6DKNsLNOD
E1sA==
X-Gm-Message-State: AOJu0YxP3ztHNVx+5fsejeA02XLC+5/p467tKnlj6B0RphbAgBcXYkyq
kTh29CIx2KOuJhFA+nFwkplcTjb3CFCLytfyRymHjTYoT5E=
X-Google-Smtp-Source: AGHT+IGo7FhYJxq+ohR1TZI7qKhpoSvRy68911YUGGT9DjXVtv/vqi5Ogv9MmN4vnucq0943SWxFQbbr+ptjbEllEUg=
X-Received: by 2002:a05:6512:318b:b0:4fd:daa0:aed8 with SMTP id
i11-20020a056512318b00b004fddaa0aed8mr15725789lfe.4.1697123245807; Thu, 12
Oct 2023 08:07:25 -0700 (PDT)
In-Reply-To: <3dqkvj-vblf3.ln1@esprimo.zbmc.eu>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <CAPTjJmp2te2wVkNjwu1EWCXZ2a0ppSgjK2axYTD5tydHE4yvzA@mail.gmail.com>
X-Mailman-Original-References: <3dqkvj-vblf3.ln1@esprimo.zbmc.eu>
 by: Chris Angelico - Thu, 12 Oct 2023 15:07 UTC

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

Re: Is a Python event polled or interrupt driven?

<3tmlvj-i0dh3.ln1@esprimo.zbmc.eu>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=24122&group=comp.lang.python#24122

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: cl...@isbd.net (Chris Green)
Newsgroups: comp.lang.python
Subject: Re: Is a Python event polled or interrupt driven?
Date: Thu, 12 Oct 2023 18:27:31 +0100
Lines: 46
Message-ID: <3tmlvj-i0dh3.ln1@esprimo.zbmc.eu>
References: <3dqkvj-vblf3.ln1@esprimo.zbmc.eu> <CAPTjJmp2te2wVkNjwu1EWCXZ2a0ppSgjK2axYTD5tydHE4yvzA@mail.gmail.com> <mailman.4.1697123248.21446.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 9i1tdvIQ4ai5us0P3kutBg+iten3nDVd2SMHNRUzPnabG9Mow=
X-Orig-Path: not-for-mail
Cancel-Lock: sha1:c9ZeDAMwSe6cd/6BcaqYXFig8XM= sha256:v/iAf6XRC5uCxGaCZLS2odQDQ5zGJRKwK8GALl2t+JI=
User-Agent: tin/2.6.2-20220130 ("Convalmore") (Linux/5.15.0-79-generic (x86_64))
 by: Chris Green - Thu, 12 Oct 2023 17:27 UTC

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
·

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor