Skip to content

bpo-32454: socket closefd#5048

Merged
tiran merged 1 commit intopython:masterfrom
tiran:socket_closefd
Jan 27, 2018
Merged

bpo-32454: socket closefd#5048
tiran merged 1 commit intopython:masterfrom
tiran:socket_closefd

Conversation

@tiran
Copy link
Copy Markdown
Member

@tiran tiran commented Dec 30, 2017

Add close(fd) function to the socket module

Signed-off-by: Christian Heimes [email protected]

NOTE The PR also documents the previously undocumented socket.close function.

https://bugs.python.org/issue32454

@tiran tiran added the type-feature A feature request or enhancement label Dec 30, 2017
Comment thread Modules/socketmodule.c Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this should be !CHECK_ERRNO(ECONNRESET), or use GET_SOCK_ERROR instead of errno.

Winsock is an OS library, so it can't use errno of a particular C runtime library. It uses Windows API [WSA]GetLastError and [WSA]SetLastError.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point!

Comment thread Doc/library/socket.rst Outdated
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.

You should add a versionadded too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The socket.dup() function exists since 2.6 at least. It just hasn't been documented yet.

Comment thread Lib/test/test_socket.py Outdated
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.

Is there already a test for dup()?

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.

Ping on this question.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, there is no test. I don't have time to write a test case, Would you like me to drop the documentation for dup?

Comment thread Lib/test/test_socket.py Outdated
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.

If it always does, then how about a assertRaises?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

assertRaises in the finally block may mask an error in the try block.

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.

Normally, Python 3 would display the exception chain.

@tiran
Copy link
Copy Markdown
Member Author

tiran commented Jan 26, 2018

@eryksun @pitrou I'd like to land this feature in 3.7.

Add close(fd) function to the socket module

Signed-off-by: Christian Heimes <[email protected]>
@tiran
Copy link
Copy Markdown
Member Author

tiran commented Jan 26, 2018

I removed the documentation for dup(fd) from this PR.

.. function:: dup(fd)
 
   Duplicate a socket file descriptor. This is like :func:`os.dup`, but for
   sockets. On some platforms (most noticeable Windows) :func:`os.dup`
   does not work for socket file descriptors.

Copy link
Copy Markdown
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Thank you Christian!

@tiran tiran merged commit d0e31b9 into python:master Jan 27, 2018
@bedevere-bot
Copy link
Copy Markdown

@tiran: Please replace # with GH- in the commit message next time. Thanks!

@tiran tiran deleted the socket_closefd branch January 27, 2018 08:54
@tiran
Copy link
Copy Markdown
Member Author

tiran commented Jan 27, 2018

thx @pitrou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants