From owner-freebsd-python@freebsd.org  Thu Sep  7 01:18:20 2017
Return-Path: <owner-freebsd-python@freebsd.org>
Delivered-To: freebsd-python@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id E2068E21898
 for <freebsd-python@mailman.ysv.freebsd.org>;
 Thu,  7 Sep 2017 01:18:20 +0000 (UTC)
 (envelope-from bugzilla-noreply@freebsd.org)
Received: from mailman.ysv.freebsd.org (unknown [127.0.1.3])
 by mx1.freebsd.org (Postfix) with ESMTP id 473EE76606
 for <freebsd-python@freebsd.org>; Thu,  7 Sep 2017 01:18:20 +0000 (UTC)
 (envelope-from bugzilla-noreply@freebsd.org)
Received: by mailman.ysv.freebsd.org (Postfix)
 id 2A022E2188D; Thu,  7 Sep 2017 01:18:20 +0000 (UTC)
Delivered-To: python@mailman.ysv.freebsd.org
Received: from mx1.freebsd.org (mx1.freebsd.org
 [IPv6:2001:1900:2254:206a::19:1])
 by mailman.ysv.freebsd.org (Postfix) with ESMTP id 298C8E2188C
 for <python@mailman.ysv.freebsd.org>; Thu,  7 Sep 2017 01:18:20 +0000 (UTC)
 (envelope-from bugzilla-noreply@freebsd.org)
Received: from kenobi.freebsd.org (kenobi.freebsd.org
 [IPv6:2001:1900:2254:206a::16:76])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (Client did not present a certificate)
 by mx1.freebsd.org (Postfix) with ESMTPS id 94236765FB
 for <python@FreeBSD.org>; Thu,  7 Sep 2017 01:18:19 +0000 (UTC)
 (envelope-from bugzilla-noreply@freebsd.org)
Received: from bugs.freebsd.org ([127.0.1.118])
 by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id v871IJ9H035462
 for <python@FreeBSD.org>; Thu, 7 Sep 2017 01:18:19 GMT
 (envelope-from bugzilla-noreply@freebsd.org)
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset="UTF-8"
From: bugzilla-noreply@freebsd.org
To: python@FreeBSD.org
Subject: maintainer-feedback requested: [Bug 222112] lang/python36
 selectors.select() does not block on named pipes / mkfifo
Date: Thu, 07 Sep 2017 01:18:19 +0000
X-Bugzilla-Type: request
X-Bugzilla-Product: Ports & Packages
X-Bugzilla-Component: Individual Port(s)
X-Bugzilla-Version: Latest
X-Bugzilla-Keywords: 
X-Bugzilla-Severity: Affects Some People
X-Bugzilla-Who: 
X-Bugzilla-Status: New
X-Bugzilla-Resolution: 
X-Bugzilla-Priority: ---
X-Bugzilla-Assigned-To: python@FreeBSD.org
X-Bugzilla-Flags: maintainer-feedback?
Message-ID: <bug-222112-21822-PMCqH6CFRD@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-222112-21822@https.bugs.freebsd.org/bugzilla/>
References: <bug-222112-21822@https.bugs.freebsd.org/bugzilla/>
X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-BeenThere: freebsd-python@freebsd.org
X-Mailman-Version: 2.1.23
Precedence: list
List-Id: FreeBSD-specific Python issues <freebsd-python.freebsd.org>
List-Unsubscribe: <https://lists.freebsd.org/mailman/options/freebsd-python>, 
 <mailto:freebsd-python-request@freebsd.org?subject=unsubscribe>
List-Archive: <http://lists.freebsd.org/pipermail/freebsd-python/>
List-Post: <mailto:freebsd-python@freebsd.org>
List-Help: <mailto:freebsd-python-request@freebsd.org?subject=help>
List-Subscribe: <https://lists.freebsd.org/mailman/listinfo/freebsd-python>,
 <mailto:freebsd-python-request@freebsd.org?subject=subscribe>
X-List-Received-Date: Thu, 07 Sep 2017 01:18:21 -0000

Jeff Kletsky <jeff+freebsd@wagsky.com> has reassigned Bugzilla Automation
<bugzilla@FreeBSD.org>'s request for maintainer-feedback to FreeBSD Python
<python@FreeBSD.org>:
Bug 222112: lang/python36 selectors.select() does not block on named pipes /
mkfifo
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D222112



--- Description ---
An instance of selectors.select() blocks as expected until data is ready on=
 a
named pipe or a regular file. On FreeBSD 11.1-RELEASE-p1 it does not block
after that data has been read from a named pipe (but does continue to block
with a regular file).=20

This is both unexpected and inconsistent with at least behavior under Mac O=
S X,
which continues to block as expected with both a named pipe and a regular f=
ile.

Observed behavior:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
* my_selectors.select() blocks as expected until data is written to the pipe
* the data is read from the pipe
* my_selectors.select() no longer blocks

Expected behavior:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
* my_selectors.select() would block until there was more data written to the
pipe


Same behavior is seen with the "default" selectors.KqueueSelector as well as
with explicitly using a selectors.PollSelector (Mac OS X default).


Impact:
=3D=3D=3D=3D=3D=3D=3D
* No clear way to use select from Python to "read when ready" from a named =
pipe
* Programs that rely on select may have very unexpected behavior


Workarounds:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(none at this time)


Environment:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
FreeBSD 11.1-RELEASE-p1
python3-3_3
python36-3.6.1_4

jailed or host system, same behavior
venv or not, same behavior


To replicate:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
(warning, this will spew to the terminal until interrupted if commands-in i=
s a
named pipe)

$ rm commands-in
$ mkfifo commands-in
(run the program, below)
$ echo "Something" >> commands-in   # ">" also fails

using 'touch' to obtain a regular file will demonstrate the regular-file
behavior

key_event_list is retained for visibility in debugger
timeout=3DNone is the default, made explicit to confirm not the issue
"If timeout is None, the call will block until a monitored file object beco=
mes
ready.=E2=80=8B"

See also https://forums.freebsd.org/threads/62377/

Example Python 3 code follows:

import logging
import selectors


def test():

    command_pipe =3D 'commands-in'

    logging.basicConfig(level=3Dlogging.INFO)
    logger =3D logging.getLogger()

    logger.info(f"Opening command pipe: '{command_pipe}'")
    with open(command_pipe, 'r') as cp:
	select_cp =3D selectors.DefaultSelector()
	select_cp.register(cp, selectors.EVENT_READ)
	while True:
	    key_event_list =3D select_cp.select(timeout=3DNone)
	    line =3D cp.readline()
	    logger.info(f"Read: '{line}'")


if __name__ =3D=3D '__main__':