--- fcgi.py-0.5.1 2002-11-20 14:54:44.000000000 -0500 +++ fcgi.py-0.5.1-hacked 2002-11-20 14:54:05.000000000 -0500 @@ -378,16 +378,17 @@ return _init = 1 + s = socket.fromfd(sys.stdin.fileno(), socket.AF_INET, socket.SOCK_STREAM) try: - s=socket.fromfd(sys.stdin.fileno(), socket.AF_INET, - socket.SOCK_STREAM) s.getpeername() - except socket.error, (err, errmsg): - if err!=errno.ENOTCONN: # must be a non-fastCGI environment - _isFCGI = 0 - return - - _sock = s + except socket.error: + # stdin not a socket -- must be a non-FastCGI environment. + _isFCGI = 0 + s.close() + return + else: + # stdin is a socket -- must be in a FastCGI environment. + _sock = s #---------------------------------------------------------------------------