Hello,
I've been working on a python3 project and I came across an issue with the open
system call that, at the very least, isn't documented. In my humble opinion,
the documentation<https://docs.python.org/3/library/functions.html#open> should
be updated because folks wouldn't expect open to be a blocking operation and
simply error out. Worse yet, open doesn't have an option to make itself
non-blocking. You have to use the os system calls to kludge a solution.
Here is how I reproduced the issue:
root@beefy:~/sandbox# mkfifo this_is_a_pipe
root@beefy:~/sandbox# ls -l this_is_a_pipe
prw-r--r-- 1 root root 0 Dec 27 14:28 this_is_a_pipe
root@beefy:~/sandbox# python3 --version
Python 3.6.7
root@beefy:~/sandbox# python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> open("this_is_a_pipe")
<blocks>
The mitigation is to use the os calls and specify to be nonblocking when
opening the file.
I'm doing this to get a fileobject and make it error out if we do have a
blocking special file:
with os.fdopen(os.open(<filename>, os.O_RDONLY| os.O_NONBLOCK) , mode='rb') as
file_obj:
I think this is mostly a documentation bug because this wouldn't be expected
behavior to someone reading the docs, but open is behaving as the fifo man
page<http://man7.org/linux/man-pages/man7/fifo.7.html> is documented. The
feature request would be to add a non-blocking option to the default open
system call.
I've also found this with some named special character files, but I don't have
a reproduction at the moment.
Thank you and have a good day!
Dan
--
https://mail.python.org/mailman/listinfo/python-list