<div dir="ltr">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.)<br></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Tue, Aug 20, 2013 at 4:57 PM, Victor Stinner <span dir="ltr"><<a href="mailto:victor.stinner@gmail.com" target="_blank">victor.stinner@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
2013/8/21 Victor Stinner <<a href="mailto:victor.stinner@gmail.com">victor.stinner@gmail.com</a>>:<br>
<div class="im">> Should I add a portable helper to the<br>
> socket module (socket.get/set_inheritable)?<br>
<br>
</div>Add the two following functions to the socket module:<br>
<br>
def get_inheritable(sock):<br>
if <a href="http://os.name" target="_blank">os.name</a> == 'nt':<br>
return os.get_handle_inheritable(sock.fileno())<br>
else:<br>
return os.get_inheritable(sock.fileno())<br>
<br>
def set_inheritable(sock, inheritable):<br>
if <a href="http://os.name" target="_blank">os.name</a> == 'nt':<br>
os.set_handle_inheritable(sock.fileno(), inheritable)<br>
else:<br>
os.set_inheritable(sock.fileno(), inheritable)<br>
<br>
Usage: socket.get_inheritable(sock) and socket.set_inheritable(sock, True)<br>
<div class="im"><br>
> Or add 2 methods to the socket class?<br>
<br>
</div>Add the two following methods to the socket class:<br>
<br>
def get_inheritable(self):<br>
if <a href="http://os.name" target="_blank">os.name</a> == 'nt':<br>
return os.get_handle_inheritable(self.fileno())<br>
else:<br>
return os.get_inheritable(self.fileno())<br>
<br>
def set_inheritable(self, inheritable):<br>
if <a href="http://os.name" target="_blank">os.name</a> == 'nt':<br>
os.set_handle_inheritable(self.fileno(), inheritable)<br>
else:<br>
os.set_inheritable(self.fileno(), inheritable)<br>
<br>
Usage: s.get_inheritable() and sock.set_inheritable(True)<br>
<div class="HOEnZb"><div class="h5"><br>
Victor<br>
_______________________________________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">http://mail.python.org/mailman/options/python-dev/guido%40python.org</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)
</div>