[Python-Dev] Re: test_asynchat.py broken on Windows

Jeremy Hylton jeremy@alum.mit.edu
Mon, 29 Oct 2001 18:20:14 -0500 (EST)


I think there are at least three things wrong, depending on what you
count as wrong.

The test is hanging because it spawns a thread, which Python will
prevent Python from exiting until the thread exits.  The thread
doesn't exit because it's waiting for input from the client.  The
client doesn't send it any input because of the exception.

thing wrong #1: It would probably make sense to change
test_asynchat.py to use a daemon thread so that it can't prevent the
test suite from exiting.

thing wrong #2: I don't think the ENONET being returned by
connect_ex() makes any sense.  My guess is that connect_ex() is (and
always has been) broken on Windows.  Could you apply this patch and
see what happens:

Index: socketmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/socketmodule.c,v
retrieving revision 1.190
diff -c -c -r1.190 socketmodule.c
*** socketmodule.c	2001/10/28 12:31:33	1.190
--- socketmodule.c	2001/10/29 23:14:18
***************
*** 1268,1274 ****
--- 1268,1278 ----
  	res = connect(s->sock_fd, addr, addrlen);
  	Py_END_ALLOW_THREADS
  	if (res != 0)
+ #ifdef MS_WINDOWS
+ 		res = WSAGetLastError();
+ #else
  		res = errno;
+ #endif
  	return PyInt_FromLong((long) res);
  }
  
thing wrong #3: From the winsock documentation for connect(), it looks
like there are more errors we should be catching in the test that
includes EWOULDBLOCK and EALREADY.  I don't think this would affect
your test, though.

thing wrong #4: It doesn't look to me like the connect() call in
test_asynchat.py is guaranteed to succeed.  It should succeed almost
every time, but there's some small chance it will fail.  Perhaps the
test should be more robust about that.

That's four things, but I don't think the last thing is all that wrong.

Jeremy