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

windwos raise OSError: [Errno 9] Bad file descriptor #1997

Closed
chenlei1998 opened this issue Apr 20, 2018 · 2 comments
Closed

windwos raise OSError: [Errno 9] Bad file descriptor #1997

chenlei1998 opened this issue Apr 20, 2018 · 2 comments

Comments

@chenlei1998
Copy link

the file ./utils/socket.py line 31 hava code os.read(socket.fileno(), n) but windows not support

my call container.exec_run("xxx", socket=False) raise:

Traceback (most recent call last):
File "E:/projects/python/judgeClient/judge.py", line 34, in
ret, s = container.exec_run("javac Main.java", workdir="/judge", socket=False)
File "D:\Python35\lib\site-packages\docker\models\containers.py", line 185, in exec_run
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket
File "D:\Python35\lib\site-packages\docker\utils\decorators.py", line 19, in wrapped
return f(self, resource_id, *args, **kwargs)
File "D:\Python35\lib\site-packages\docker\api\exec_api.py", line 165, in exec_start
return self._read_from_socket(res, stream, tty)
File "D:\Python35\lib\site-packages\docker\api\client.py", line 373, in _read_from_socket
return six.binary_type().join(gen)
File "D:\Python35\lib\site-packages\docker\utils\socket.py", line 75, in frames_iter
n = next_frame_size(socket)
File "D:\Python35\lib\site-packages\docker\utils\socket.py", line 62, in next_frame_size
data = read_exactly(socket, 8)
File "D:\Python35\lib\site-packages\docker\utils\socket.py", line 47, in read_exactly
next_data = read(socket, n - len(data))
File "D:\Python35\lib\site-packages\docker\utils\socket.py", line 32, in read
return os.read(socket.fileno(), n)
OSError: [Errno 9] Bad file descriptor

@zhangyanwei
Copy link

I met same error, is there a workaround ?

@chenlei1998
Copy link
Author

@zhangyanwei
rewrite read function in utils\socket.py

def read(socket, n=4096):
    """
    Reads at most n bytes from socket
    """

    recoverable_errors = (errno.EINTR, errno.EDEADLK, errno.EWOULDBLOCK)

    if six.PY3 and not isinstance(socket, NpipeSocket):
        select.select([socket], [], [])

    try:
        if hasattr(socket, 'recv'):
            return socket.recv(n)
        # fix OSError
        try:
            return os.read(socket.fileno(), n)
        except OSError:
            return socket.read(n)
    except EnvironmentError as e:
        if e.errno not in recoverable_errors:
            raise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants