Search code examples
pythonsocketstornadonio

Getting BlockingIOError (WinError 10035) when accepting a socket


I've gotten a chance to work again with Python, but this time I decided to take Python 3.5 to my journey.

I had to port a working non-blocking socket server using Tornado, from Python 2.7 to 3.5. Used same source code, but this time it doesn't work as needed.

I keep getting [WinError 10035] A non-blocking socket operation could not be completed immediately on send whenever I accept a socket connection using socket.accept() and I still can't figure out why.

Tried to use example code that I've found a few years ago on GitHub Gist and still keep getting an error. Is there any changes in socket library or is it just a bug?


Solution

  • This error is harmless and expected. The problem is that the gist you linked to doesn't know about windows-specific error codes (on line 24 it checks for EWOULDBLOCK and EAGAIN, but it should also use WSAEWOULDBLOCK).

    Since that gist was written, Tornado has gained some new utilities to make this easier. If you're using IOStreams, you can use tornado.tcpserver.TCPServer to accept your connections, or if you want to continue using plain sockets you can use the lower-level tornado.netutil.add_accept_handler.