From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72BFCC7EE26 for ; Tue, 23 May 2023 12:19:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236557AbjEWMTS (ORCPT ); Tue, 23 May 2023 08:19:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234997AbjEWMTR (ORCPT ); Tue, 23 May 2023 08:19:17 -0400 Received: from fgw23-7.mail.saunalahti.fi (fgw23-7.mail.saunalahti.fi [62.142.5.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43B93130 for ; Tue, 23 May 2023 05:19:08 -0700 (PDT) Received: from localhost (88-113-26-95.elisa-laajakaista.fi [88.113.26.95]) by fgw23.mail.saunalahti.fi (Halon) with ESMTP id f9c03db6-f963-11ed-b972-005056bdfda7; Tue, 23 May 2023 15:18:50 +0300 (EEST) From: andy.shevchenko@gmail.com Date: Tue, 23 May 2023 15:18:50 +0300 To: Bartosz Golaszewski Cc: Nicolas Frattaroli , linux-gpio@vger.kernel.org Subject: Re: [libgpiod] [RFC PATCH] bindings: python: allow specifying infinite timeout Message-ID: References: <20230519174619.58308-1-frattaroli.nicolas@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Tue, May 23, 2023 at 12:06:47PM +0200, Bartosz Golaszewski kirjoitti: > On Fri, May 19, 2023 at 7:47 PM Nicolas Frattaroli > wrote: > > So far, libgpiod's Python bindings had no way to state that a > > user wishes to wait for events indefinitely, as a timeout of > > None would intentionally be converted to 0 seconds, i.e. return > > from the select call in poll_fd immediately. > > > > The usual Python convention and even the select convention is > > to block indefinitely on a timeout=None. However, changing the > > poll_fd function to do this now would change an (intentional) > > API design choice by libgpiod 2.0 that API users presumably > > rely on. > > > > By allowing float("inf") (or in fact math.inf, or your favourite > > other way to get an infinite float) to mean waiting infinitely > > solves this by extending the API rather than changing it. > > > > On gpiod Python bindings without this change, passing inf results > > in an OverflowError being raised in select. API users who wish to > > support older versions of the bindings can catch this exception and > > act on it. ... > I like this approach too. In fact - it may be even clearer and more > intuitive than converting None to infinite timeout. With all respect to the clever design solutions I would rather go the de facto Pythonic way. If the native libraries use None for indefinite then it's better to do that way, otherwise we will add quite a confusion to the Python users. > Any objections against using negative numbers for the same purpose as well? The question here is: What in the very same situations are other (presumably native) Python libraries using? -- With Best Regards, Andy Shevchenko