From a868b1c857e43d538e3d613919df67f49b846eb8 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Fri, 8 Jan 2010 10:06:20 -0800 Subject: [PATCH] Improved error reporting when we are on Windows and try to do something that Windows doesn't support. Patch from Nat. --- eventlet/greenio.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/eventlet/greenio.py b/eventlet/greenio.py index 0d6d1be..636039e 100644 --- a/eventlet/greenio.py +++ b/eventlet/greenio.py @@ -143,8 +143,22 @@ def set_nonblocking(fd): try: setblocking = fd.setblocking except AttributeError: - # This version of Python predates socket.setblocking() - import fcntl + # fd has no setblocking() method. It could be that this version of + # Python predates socket.setblocking(). In that case, we can still set + # the flag "by hand" on the underlying OS fileno using the fcntl + # module. + try: + import fcntl + except ImportError: + # Whoops, Windows has no fcntl module. This might not be a socket + # at all, but rather a file-like object with no setblocking() + # method. In particular, on Windows, pipes don't support + # non-blocking I/O and therefore don't have that method. Which + # means fcntl wouldn't help even if we could load it. + raise NotImplementedError("set_nonblocking() on a file object " + "with no setblocking() method " + "(Windows pipes don't support non-blocking I/O)") + # We managed to import fcntl. fileno = fd.fileno() flags = fcntl.fcntl(fileno, fcntl.F_GETFL) fcntl.fcntl(fileno, fcntl.F_SETFL, flags | os.O_NONBLOCK)