From 30ffaf6073845d87a3d49594ac64552027589ced Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 7 Jun 2009 22:10:27 -0700 Subject: [PATCH] Nat's patch for making greenio successfully import under Windows by deferring the import of fcntl. --- eventlet/greenio.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/eventlet/greenio.py b/eventlet/greenio.py index da9604e..6be9ecc 100644 --- a/eventlet/greenio.py +++ b/eventlet/greenio.py @@ -32,7 +32,6 @@ import errno import os import socket from socket import socket as _original_socket -import fcntl import time @@ -169,14 +168,17 @@ def file_send(fd, data): def set_nonblocking(fd): - ## Socket - if hasattr(fd, 'setblocking'): - fd.setblocking(0) - ## File - else: + try: + setblocking = fd.setblocking + except AttributeError: + # This version of Python predates socket.setblocking() + import fcntl fileno = fd.fileno() flags = fcntl.fcntl(fileno, fcntl.F_GETFL) fcntl.fcntl(fileno, fcntl.F_SETFL, flags | os.O_NONBLOCK) + else: + # socket supports setblocking() + setblocking(0) class GreenSocket(object):