linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Darrien <darrien@freenet.de>,
	Viresh Kumar <viresh.kumar@linaro.org>, Jiri Benc <jbenc@upir.cz>,
	Joel Savitz <joelsavitz@gmail.com>,
	"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: [libgpiod v2][PATCH v2 5/5] bindings: python: add the implementation for v2 API
Date: Fri, 1 Jul 2022 15:33:38 +0800	[thread overview]
Message-ID: <20220701073338.GA33559@sol> (raw)
In-Reply-To: <CAMRc=McwhnjovSB7RuZQTnZ9tKww=WDvk813Wbmt5PYaK95cPA@mail.gmail.com>

On Fri, Jul 01, 2022 at 09:29:53AM +0200, Bartosz Golaszewski wrote:
> On Fri, Jul 1, 2022 at 9:27 AM Kent Gibson <warthog618@gmail.com> wrote:
> >
> > On Fri, Jul 01, 2022 at 09:21:58AM +0200, Bartosz Golaszewski wrote:
> > > On Fri, Jul 1, 2022 at 8:07 AM Kent Gibson <warthog618@gmail.com> wrote:
> > > >
> > > > On Thu, Jun 30, 2022 at 04:38:51PM +0800, Kent Gibson wrote:
> > > > > On Thu, Jun 30, 2022 at 04:14:50PM +0800, Kent Gibson wrote:
> > > > > > On Thu, Jun 30, 2022 at 08:54:24AM +0200, Bartosz Golaszewski wrote:
> > > > > > > On Thu, Jun 30, 2022 at 4:25 AM Kent Gibson <warthog618@gmail.com> wrote:
> > > > > > > >
> > > > > > > > On Tue, Jun 28, 2022 at 10:42:26AM +0200, Bartosz Golaszewski wrote:
> > > > > > > > > This is the implementation of the new python API for libgpiod v2.
> > > > > > > > >
> > > > > > > >
> > > > > > > > [snip]
> > > > > > > >
> > > > > > > > > +     }
> > > > > > > > > +
> > > > > > > > > +     res = PyObject_Call(method, args, line_cfg_kwargs);
> > > > > > > > > +     Py_DECREF(args);
> > > > > > > > > +     Py_DECREF(method);
> > > > > > > > > +     if (!Py_IsNone(res)) {
> > > > > > > > > +             Py_DECREF(res);
> > > > > > > > > +             return NULL;
> > > > > > > > > +     }
> > > > > > > > > +
> > > > > > > >
> > > > > > > > Building against python 3.9 (the min required by configure.ac) gives:
> > > > > > > >
> > > > > > > > module.c:276:7: warning: implicit declaration of function ‘Py_IsNone’; did you mean ‘Py_None’? [-Wimplicit-function-declaration]
> > > > > > > >   276 |  if (!Py_IsNone(res)) {
> > > > > > > >       |       ^~~~~~~~~
> > > > > > > >       |       Py_None
> > > > > > > >
> > > > > > > >
> > > > > > > > Py_IsNone didn't get added to the Stable ABI until 3.10.
> > > > > > > >
> > > > > > > > Cheers,
> > > > > > > > Kent.
> > > > > > >
> > > > > > > It seems like most distros still ship python 3.9, I don't want to make
> > > > > > > 3.10 the requirement. This can be replaced by `if (res != Py_None)`.
> > > > > > > Are there any more build issues?
> > > > > > >
> > > > > >
> > > > > > No, that was the only one.
> > > > > >
> > > > >
> > > > > But I am seeing a test failure:
> > > > >
> > > > > $ sudo bindings/python/tests/gpiod_py_test.py
> > > > > .............................................................................F................................
> > > > > ======================================================================
> > > > > FAIL: test_module_line_request_edge_detection (cases.tests_line_request.ModuleLineRequestWorks)
> > > > > ----------------------------------------------------------------------
> > > > > Traceback (most recent call last):
> > > > >   File "/home/dev/libgpiod/bindings/python/tests/cases/tests_line_request.py", line 71, in test_module_line_request_edge_detection
> > > > >     self.assertTrue(req.wait_edge_event())
> > > > > AssertionError: False is not true
> > > > >
> > > > > ----------------------------------------------------------------------
> > > > > Ran 110 tests in 2.652s
> > > > >
> > > > > FAILED (failures=1)
> > > > >
> > > >
> > > > The req.wait_edge_event() does not wait without a timeout parameter,
> > > > which is a bit nonintuitive, so the test has a race.
> > >
> > > Ah, makes sense.
> > >
> > > > Adding a timeout=datetime.timedelta(microseconds=1) (the shortest
> > > > possible) works for me, so anything that triggers a context switch is
> > > > probably sufficient, though a longer timeout probably wouldn't hurt.
> > > >
> > >
> > > I'll change that.
> > >
> > > > The Python API should take timeout=NONE to mean wait indefinitely, and
> > > > 0 as a poll.
> > >
> > > This makes sense but I'd still want to have some default behavior for
> > > when timeout is not given. Maybe wait indefinitely?
> >
> > That is what I said - you get timeout=None if the kwarg is not specified.
> >
> > >
> > > > And it should take the timeout as a float, not a
> > > > timedelta, as per select.select.  From its doc:
> > >
> > > I don't necessarily want to mirror select's interface. Why would we
> > > prefer a float over a class that's the standard python interface for
> > > storing time deltas?
> > >
> >
> > Cos you are forcing the user to create a timedelta, which is a PITA,
> > and both time.sleep and select.select (i.e. standard Python modules)
> > do it that way.  The float is the Pythonic way.
> >
> 
> Timedelta constructor is much more explicit than a float IMO. How
> about a compromise and taking both (mutually exclusive)?
> timeout=datettime.timedelta(seconds=1) == timeout_sec=float(1.0)?
> 

Maybe, but float seconds seems to be the way they do it.
If you insist on both then just the one timeout parameter and work the
type out on the fly. (it's Python, so dynamic typing...)

Cheers,
Kent.

  reply	other threads:[~2022-07-01  7:33 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-28  8:42 [libgpiod v2][PATCH v2 0/5] bindings: implement python bindings for libgpiod v2 Bartosz Golaszewski
2022-06-28  8:42 ` [libgpiod v2][PATCH v2 1/5] bindings: python: remove old version Bartosz Golaszewski
2022-06-28  8:42 ` [libgpiod v2][PATCH v2 2/5] bindings: python: enum: add a piece of common code for using python's enums from C Bartosz Golaszewski
2022-06-28  8:42 ` [libgpiod v2][PATCH v2 3/5] bindings: python: add examples for v2 API Bartosz Golaszewski
2022-06-28  8:42 ` [libgpiod v2][PATCH v2 4/5] bindings: python: add tests " Bartosz Golaszewski
2022-07-05  2:08   ` Kent Gibson
2022-07-07 10:17     ` Bartosz Golaszewski
2022-07-07 12:22       ` Kent Gibson
2022-06-28  8:42 ` [libgpiod v2][PATCH v2 5/5] bindings: python: add the implementation " Bartosz Golaszewski
2022-06-30  2:25   ` Kent Gibson
2022-06-30  6:54     ` Bartosz Golaszewski
2022-06-30  8:14       ` Kent Gibson
2022-06-30  8:38         ` Kent Gibson
2022-07-01  6:07           ` Kent Gibson
2022-07-01  7:21             ` Bartosz Golaszewski
2022-07-01  7:26               ` Kent Gibson
2022-07-01  7:29                 ` Bartosz Golaszewski
2022-07-01  7:33                   ` Kent Gibson [this message]
2022-07-01  8:02                     ` Kent Gibson
2022-07-01  8:18                       ` Bartosz Golaszewski
2022-07-01  8:32                         ` Bartosz Golaszewski
2022-07-01  8:52                           ` Kent Gibson
2022-07-01  9:28                             ` Bartosz Golaszewski
2022-07-01  8:32                         ` Kent Gibson
2022-07-05  2:09   ` Kent Gibson
2022-07-07 12:19     ` Bartosz Golaszewski
2022-07-07 13:09       ` Kent Gibson
2022-07-07 20:09         ` Bartosz Golaszewski
2022-07-08  1:38           ` Kent Gibson
2022-07-08  9:49             ` Bartosz Golaszewski
2022-07-08 10:56               ` Kent Gibson
2022-07-08 11:28                 ` Bartosz Golaszewski
2022-07-08 15:26                   ` Bartosz Golaszewski
2022-07-08 15:58                     ` Kent Gibson
2022-06-28  8:47 ` [libgpiod v2][PATCH v2 0/5] bindings: implement python bindings for libgpiod v2 Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220701073338.GA33559@sol \
    --to=warthog618@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=darrien@freenet.de \
    --cc=jbenc@upir.cz \
    --cc=joelsavitz@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).