After testing the test on Unix, several improvements:
authorGuido van Rossum <guido@python.org>
Fri, 6 Apr 2001 16:43:49 +0000 (16:43 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 6 Apr 2001 16:43:49 +0000 (16:43 +0000)
- Use push() instead of send(), and make these calls in main().

- Sleep a second to give the server thread time to initialize itself.

Lib/test/test_asynchat.py

index 3d31524e6227b52448ba8f1124a91a8874e1e005..c887cec6ae3821a812128d9d608cfcf82a853170 100644 (file)
@@ -1,6 +1,6 @@
 # test asynchat -- requires threading
 
-import asyncore, asynchat, socket, threading
+import asyncore, asynchat, socket, threading, time
 
 HOST = "127.0.0.1"
 PORT = 54321
@@ -32,8 +32,6 @@ class echo_client(asynchat.async_chat):
         self.connect((HOST, PORT))
         self.set_terminator("\n")
         self.buffer = ""
-        self.send("hello ")
-        self.send("world\n")
 
     def handle_connect(self):
         print "Connected"
@@ -49,7 +47,10 @@ class echo_client(asynchat.async_chat):
 def main():
     s = echo_server()
     s.start()
+    time.sleep(1) # Give server time to initialize
     c = echo_client()
+    c.push("hello ")
+    c.push("world\n")
     asyncore.loop()
 
 main()