Commit 8fed3827 authored by Jason Madden's avatar Jason Madden

socketpair and subprocess.STARTUPINFO for py 3.6/windows

parent b0800428
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
================== ==================
- CI services now test on 3.6.0. - CI services now test on 3.6.0.
- Windows: Provide ``socket.socketpair`` on 3.6.
- Windows: List ``subprocess.STARTUPINFO`` in ``subprocess.__all__``
on 3.6.
- The ``_DummyThread`` objects created by calling - The ``_DummyThread`` objects created by calling
:func:`threading.current_thread` from inside a raw :func:`threading.current_thread` from inside a raw
:class:`greenlet.greenlet` now clean up after themselves when the :class:`greenlet.greenlet` now clean up after themselves when the
......
...@@ -654,9 +654,48 @@ if hasattr(_socket, "socketpair"): ...@@ -654,9 +654,48 @@ if hasattr(_socket, "socketpair"):
a = socket(family, type, proto, a.detach()) a = socket(family, type, proto, a.detach())
b = socket(family, type, proto, b.detach()) b = socket(family, type, proto, b.detach())
return a, b return a, b
elif sys.version_info[:2] >= (3, 6):
# Origin: https://gist.github.com/4325783, by Geert Jansen. Public domain.
# gevent: taken from 3.6 release. Expected to be used only on Win/3.6
def socketpair(family=AF_INET, type=SOCK_STREAM, proto=0):
if family == AF_INET:
host = _LOCALHOST
elif family == AF_INET6:
host = _LOCALHOST_V6
else:
raise ValueError("Only AF_INET and AF_INET6 socket address families "
"are supported")
if type != SOCK_STREAM:
raise ValueError("Only SOCK_STREAM socket type is supported")
if proto != 0:
raise ValueError("Only protocol zero is supported")
# We create a connected TCP socket. Note the trick with
# setblocking(False) that prevents us from having to create a thread.
lsock = socket(family, type, proto)
try:
lsock.bind((host, 0))
lsock.listen()
# On IPv6, ignore flow_info and scope_id
addr, port = lsock.getsockname()[:2]
csock = socket(family, type, proto)
try:
csock.setblocking(False)
try:
csock.connect((addr, port))
except (BlockingIOError, InterruptedError):
pass
csock.setblocking(True)
ssock, _ = lsock.accept()
except:
csock.close()
raise
finally:
lsock.close()
return (ssock, csock)
elif 'socketpair' in __implements__: elif 'socketpair' in __implements__:
# Win32: not available # Win32: not available prior to 3.6
# Multiple imports can cause this to be missing if _socketcommon # Multiple imports can cause this to be missing if _socketcommon
# was successfully imported, leading to subsequent imports to cause # was successfully imported, leading to subsequent imports to cause
# ValueError # ValueError
......
...@@ -141,6 +141,11 @@ if sys.version_info[:2] >= (3, 5): ...@@ -141,6 +141,11 @@ if sys.version_info[:2] >= (3, 5):
except: except:
MAXFD = 256 MAXFD = 256
if sys.version_info[:2] >= (3, 6):
# This was added to __all__ for windows in 3.6
__extra__.remove('STARTUPINFO')
__implements__.append('STARTUPINFO')
actually_imported = copy_globals(__subprocess__, globals(), actually_imported = copy_globals(__subprocess__, globals(),
only_names=__imports__, only_names=__imports__,
ignore_missing_names=True) ignore_missing_names=True)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment