Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,8 +619,9 @@ def getsockopt(self, level, optname, buflen=None):
def close(self):
if self.fd < 0:
return
os.close(self.fd)
fd = self.fd
self.fd = -1
os.close(fd)

def fileno(self):
return self.fd
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_asyncore.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,10 @@ def test_close_twice(self):
f = asyncore.file_wrapper(fd)
os.close(fd)

f.close()
os.close(f.fd) # file_wrapper dupped fd
with self.assertRaises(OSError):
f.close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this test here:

self.assertEqual(f.fileno(), -1)

To test your fix.


self.assertEqual(f.fd, -1)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Haypo isn't this ^^^^ good enough?

Since file_wrapper.fd is not documented, maybe we should replace f.fd with f.fileno()? Do you want to add this change to the patch?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed it :-) It's enough.

# calling close twice should not fail
f.close()
Expand Down