Summary: | lang/python36 selectors.select() does not block on named pipes / mkfifo | ||
---|---|---|---|
Product: | Ports & Packages | Reporter: | Jeff Kletsky <jeff+freebsd> |
Component: | Individual Port(s) | Assignee: | freebsd-python (Nobody) <python> |
Status: | Closed Works As Intended | ||
Severity: | Affects Some People | Flags: | bugzilla:
maintainer-feedback?
(python) |
Priority: | --- | ||
Version: | Latest | ||
Hardware: | Any | ||
OS: | Any |
Description
Jeff Kletsky
2017-09-07 01:18:19 UTC
Based on tobic@ comment, this does not appear to be a bug, but an outcome of how FIFOs are implemented. https://forums.freebsd.org/threads/62377/#post-360237 Looking at this on an Ubuntu system and a similar Python version shows similar behavior to that seen under FreeBSD. It appears that Mac OS X is "different" in how it is implemented. Closing as "works as intended" @tobic code, for anyone that finds this through search: After opening the FIFO for reading, open it again for writing to prevent your program from ever seeing EOF at all (i.e. pretend there is always at least 1 writer). There is no need to use select() here; readline() will already block and wait for new data. Code: import logging 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, open(command_pipe, "w"): while True: line = cp.readline() logger.info(f"Read: '{line}'") if __name__ == '__main__': test() |