After getting my code running "properly" under Mac OS X and Python 3.6, I moved it over to a jail on FreeBSD 11.1-RELEASE-p1 and python36-3.6.1_4 and found that selectors.select() would block as expected until the first data was written to and read from the pipe, but then no longer block (unexpected). If I use a regular file on FreeBSD, it behaves as expected, blocking until more data is written to the file.
Has anyone run into this before?
The goal of the code behind the stripped-down example here is to allow "any" other process/script to easily pass short bits data ("commands") to a running Python program. I'm open to any solutions, as well as "better" ways of accomplishing the goal.
Works:
Fails (be prepared to ^C the program!):
Looking at key_event_list in the debugger shows that it does not change once "triggered" when reading from a pipe.
selectors.DefaultSelector() returns a selectors.KqueueSelector object under FreeBSD 11.1. Under Mac OS X, it returns a selectors.PollSelector object.
Changing to select_cp = selectors.PollSelector() does not change the behavior for a named pipe under FreeBSD.
select(timeout=None) should block until one (or more, if there were any) monitored file objects are ready. None is the stated default, but was made explicit to ensure it was properly set.
edit: same behavior seen for the C-esque select.select([cp], [], []) with no timeout (blocking)
Has anyone run into this before?
The goal of the code behind the stripped-down example here is to allow "any" other process/script to easily pass short bits data ("commands") to a running Python program. I'm open to any solutions, as well as "better" ways of accomplishing the goal.
Works:
$ rm commands-in
$ touch commands-in
(run the program, while running)
$ echo "Some data" >> commands-in
$ touch commands-in
(run the program, while running)
$ echo "Some data" >> commands-in
Fails (be prepared to ^C the program!):
$ rm commands-in
$ mkfifo commands-in
(run the program, while running)
$ echo "Some data" >> commands-in # ">" also fails
$ mkfifo commands-in
(run the program, while running)
$ echo "Some data" >> commands-in # ">" also fails
Looking at key_event_list in the debugger shows that it does not change once "triggered" when reading from a pipe.
selectors.DefaultSelector() returns a selectors.KqueueSelector object under FreeBSD 11.1. Under Mac OS X, it returns a selectors.PollSelector object.
Changing to select_cp = selectors.PollSelector() does not change the behavior for a named pipe under FreeBSD.
select(timeout=None) should block until one (or more, if there were any) monitored file objects are ready. None is the stated default, but was made explicit to ensure it was properly set.
If timeout is None, the call will block until a monitored file object becomes ready.
edit: same behavior seen for the C-esque select.select([cp], [], []) with no timeout (blocking)
Code:
import logging
import selectors
def test():
command_pipe = 'commands-in'
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger()
logger.info(f"Opening command pipe: '{command_pipe}'")
with open(command_pipe, 'r') as cp:
select_cp = selectors.DefaultSelector()
select_cp.register(cp, selectors.EVENT_READ)
while True:
key_event_list = select_cp.select(timeout=None)
line = cp.readline()
logger.info(f"Read: '{line}'")
if __name__ == '__main__':
test()