Title: os.fdlistdir() should not close the file descriptor given in argument
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.3
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: neologix, pitrou, python-dev, rosslagerwall
Priority: normal Keywords: patch

Created on 2012-01-10 18:56 by neologix, last changed 2012-01-10 20:40 by neologix. This issue is now closed.

File name Uploaded Description Edit
fdlistdir_noclose.diff neologix, 2012-01-10 18:56 review
Messages (5)
msg151023 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2012-01-10 18:56
os.fdlistdir() closes the FD passed as argument.
This is annoying, since in 99% of the cases you'd like to keep FD intact, so you end up doing os.fdlistdir(os.dup(fd)).
Here's a patch that duplicates the FD in fdlistdir(), so that the original FD is kept intact, which is much more natural (at least to me :).
That's an API change, but since fdlistdir() has been introduced in 3.3 which hasn't been released yet, I think it should be acceptable.
msg151024 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-01-10 18:58
Agreed with the change.
msg151025 - (view) Author: Ross Lagerwall (rosslagerwall) (Python committer) Date: 2012-01-10 19:00
The reason I made it like that was that it seemed "closer" to the fdopendir() function which steals the fd for internal use.

However, I agree that it makes more sense to dup() it.

Patch looks good.
msg151027 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-01-10 19:25
New changeset 6d395ed03f95 by Charles-François Natali in branch 'default':
Issue #13757: Change os.fdlistdir() so that it duplicates the passed file
msg151029 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2012-01-10 20:40
Date User Action Args
2012-01-10 20:40:19neologixsetstatus: open -> closed
resolution: fixed
messages: + msg151029

stage: resolved
2012-01-10 19:25:46python-devsetnosy: + python-dev
messages: + msg151027
2012-01-10 19:00:28rosslagerwallsetmessages: + msg151025
2012-01-10 18:58:46pitrousetmessages: + msg151024
2012-01-10 18:56:51neologixcreate