-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OSError opening same fd twice #997
Comments
Thanks! I somewhat expected new issues to crop up with that change, as the tests cover only a small part of the possible usages...
That was just an observation of the behavior in the real file system, at least with the tests I ran. Pypi often behave slightly different compared to CPython - I did not investigate the cause. You probably have to pin |
Hm, I'm having trouble understanding the behavior in the real file system. If I create a file fd = my_file.fileno()
readf = open(fd, "rb", buffering=0)
writef = open(fd, "wb", buffering=0, closefd=False)
os.close(fd) this works. If I do instead: fd = my_file.fileno()
open(fd, "rb", buffering=0)
open(fd, "wb", buffering=0, closefd=False)
os.close(fd) e.g. the same, but not assigning the created file to a variable, I get an OSError (invalid file handle) on the second I'm just recording this for reference, I'm a bit stumped at the moment... |
After writing this, I realized that this means that the file is closed if it is not assigned as in the second case, which explains the invalid file descriptor. This explains the behavior, though I will have to rethink the logic here - I'm not sure how to correctly implement this. This may take some time... |
So, to sum this up: I will remove the ugly code that caused this and reopen the issue which I had fixed by that. Now that I understand that this is a reference counting / garbage collection problem, it is also clear why the behavior is different in pypy. The file is closed if the file object is released, which only can happen immediately after the line it was created, if the file is a C object. With a Python implementation (pypy) this will happen later when the garbage collector kicks in. I have no idea yet what to do about that other issue without adding C code to pyfakefs (which I really don't want to), but that is something unrelated to this issue. |
Actually I don't have to reopen the other issue, as this specific behavior was not a part of the issue. |
@carlmontanari - I'm going to handle another issue first, and make a new release after that. |
The other issue may take a bit longer, so I decided to make a patch release now - done. |
Describe the bug
Describe the observed behavior, and what you expect to happen instead.
In case of a crash, please provide the complete stack trace.
👋 in the recent release there were some changes around opening fake files and checking their permissions in #967 which resulted in #983 it looks like.
I have a situation (repro below) where I open the same fd twice and create an io.BufferedRWPair -- with this latest update this fails with the below exception as the file is already opened once.
To be honest im not sure this is a bug or if what I have is not very sane/smart -- the relevant bits for me where vendor'd from pexepct/ptyprocess and ive pretty much left it alone for forever :)
What is/was the reason for only allowing things that aren't pypy to open a file once?
How To Reproduce
Please provide a unit test or a minimal reproducible example that shows
the problem.
Your environment
Please run the following in the environment where the problem happened and
paste the output.
Thanks a bunch for this project, been using it in testing for a long time and its always been so nice and easy to work with!
carl
The text was updated successfully, but these errors were encountered: