Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Fix OSError on spawning of PtyProcess #88

Merged
merged 1 commit into from
Jan 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions winpty/ptyprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def __init__(self, pty):

# Set up our file reader sockets.
self._server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = _get_address()
self._server.bind(address)
self._server.bind(("127.0.0.1", 0))
address = self._server.getsockname()
self._server.listen(1)

# Read from the pty in a thread.
Expand Down Expand Up @@ -349,24 +349,6 @@ def _read_in_thread(address, pty):
client.close()


def _get_address(default_port=20128):
"""Find and return a non used port"""
while True:
try:
sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM,
socket.IPPROTO_TCP)
sock.bind(("127.0.0.1", default_port))
except socket.error as _msg: # analysis:ignore
default_port += 1
else:
break
finally:
sock.close()
sock = None
return ("127.0.0.1", default_port)


def _unicode(s):
"""Ensure that a string is Unicode on Python 2.
"""
Expand Down