[docs] [issue26703] Socket state corrupts when original socket object goes out of scope in a different thread

Antoine Pitrou report at bugs.python.org
Thu Apr 7 02:44:52 EDT 2016


Antoine Pitrou added the comment:

The general answer here is you should avoid mixing calls to different abstraction layers. Either use only the file descriptor or only the socket object.

This is not limited to lifetime issues, other issues can occur. For example, setting a timeout on a socket puts the underlying file descriptor in non-blocking mode. So code using the file descriptor can fail with EAGAIN.

If you really want to use *both* a file descriptor and a socket object, you can use os.dup() on the file descriptor, so that the OS resources are truly independent.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26703>
_______________________________________


More information about the docs mailing list