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

OSError: [WinError 10038] #1

Closed
bitsgalore opened this issue May 17, 2019 · 3 comments
Closed

OSError: [WinError 10038] #1

bitsgalore opened this issue May 17, 2019 · 3 comments

Comments

@bitsgalore
Copy link
Member

bitsgalore commented May 17, 2019

From time to time the following error occurs:

starting connection to ('127.0.0.1', 65432)
Traceback (most recent call last):
File "f:\johan\pythonCode\socketclient\client-launch.py", line 8, in <module>
    main()
File "f:\johan\pythonCode\socketclient\socketclient\client\client.py", line 10
7, in main
    myClient.send_request(host, port, fieldName, value)
File "f:\johan\pythonCode\socketclient\socketclient\client\client.py", line 52
, in send_request
    events = self.sel.select(timeout=1)
File "c:\Python36\lib\selectors.py", line 323, in select
    r, w, _ = self._select(self._readers, self._writers, [], timeout)
File "c:\Python36\lib\selectors.py", line 314, in _select
    r, w, x = select.select(r, w, w, timeout)
OSError: [WinError 10038] An operation was attempted on something that is not a
socket

Not clears what triggers it, seems to happen pretty randomly and unrelated to the input used.

@bitsgalore
Copy link
Member Author

bitsgalore commented May 17, 2019

Could be a bug in Python:

https://bugs.python.org/issue34795

This looks similar:

Rapptz/discord.py#1819

@bitsgalore
Copy link
Member Author

Also closing sock directly using this modification:

def start_connection(self, host, port, request):
addr = (host, port)
print("starting connection to", addr)
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.setblocking(False)
self.sock.connect_ex(addr)
events = selectors.EVENT_READ | selectors.EVENT_WRITE
message = libclient.Message(self.sel, self.sock, addr, request)
self.sel.register(self.sock, events, data=message)

def send_request(self, host, port, fieldName, value):
    request = self.create_request(fieldName, value)
    self.start_connection(host, port, request)

    try:
        while True:
            events = self.sel.select(timeout=1)
            for key, mask in events:
                message = key.data
                try:
                    message.process_events(mask)
                except Exception:
                    print(
                        "main: error: exception for",
                        f"{message.addr}:\n{traceback.format_exc()}",
                    )
                    #message.close()
                    self.sock.close()
            # Check for a socket being monitored to continue.
            if not self.sel.get_map():
                break
    except KeyboardInterrupt:
        print("caught keyboard interrupt, exiting")
    finally:
        self.sel.close()

But this makes no difference.

@bitsgalore
Copy link
Member Author

Replacing the existing socket code by the much simpler code adapted from here appears to solve this issue:

74333c5

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

No branches or pull requests

1 participant