[Python-Dev] PEP 446: issue with sockets (original) (raw)

Guido van Rossum guido at python.org
Wed Aug 21 02:07:23 CEST 2013


Since this is a new API and only applies to sockets, making them methods sounds good. (I'd put the 'nt' test outside the method defs though so they are tested only once per import.)

On Tue, Aug 20, 2013 at 4:57 PM, Victor Stinner <victor.stinner at gmail.com>wrote:

2013/8/21 Victor Stinner <victor.stinner at gmail.com>: > Should I add a portable helper to the > socket module (socket.get/setinheritable)?

Add the two following functions to the socket module: def getinheritable(sock): if os.name == 'nt': return os.gethandleinheritable(sock.fileno()) else: return os.getinheritable(sock.fileno()) def setinheritable(sock, inheritable): if os.name == 'nt': os.sethandleinheritable(sock.fileno(), inheritable) else: os.setinheritable(sock.fileno(), inheritable) Usage: socket.getinheritable(sock) and socket.setinheritable(sock, True) > Or add 2 methods to the socket class? Add the two following methods to the socket class: def getinheritable(self): if os.name == 'nt': return os.gethandleinheritable(self.fileno()) else: return os.getinheritable(self.fileno()) def setinheritable(self, inheritable): if os.name == 'nt': os.sethandleinheritable(self.fileno(), inheritable) else: os.setinheritable(self.fileno(), inheritable) Usage: s.getinheritable() and sock.setinheritable(True) Victor


Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org

-- --Guido van Rossum (python.org/~guido) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130820/5c5dcf9f/attachment.html>



More information about the Python-Dev mailing list