[Python-3000-checkins] r57997 - python/branches/py3k/Lib/test/test_ftplib.py

guido.van.rossum python-3000-checkins at python.org
Thu Sep 6 05:57:24 CEST 2007


Author: guido.van.rossum
Date: Thu Sep  6 05:57:23 2007
New Revision: 57997

Modified:
   python/branches/py3k/Lib/test/test_ftplib.py
Log:
Use an event variable to wait for the server to be ready, not time.sleep().


Modified: python/branches/py3k/Lib/test/test_ftplib.py
==============================================================================
--- python/branches/py3k/Lib/test/test_ftplib.py	(original)
+++ python/branches/py3k/Lib/test/test_ftplib.py	Thu Sep  6 05:57:23 2007
@@ -6,12 +6,13 @@
 from unittest import TestCase
 from test import test_support
 
-def server(evt):
+def server(evt, ready):
     serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     serv.settimeout(3)
     serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     serv.bind(("", 9091))
     serv.listen(5)
+    ready.set()
     try:
         conn, addr = serv.accept()
     except socket.timeout:
@@ -28,8 +29,9 @@
     def setUp(self):
         ftplib.FTP.port = 9091
         self.evt = threading.Event()
-        threading.Thread(target=server, args=(self.evt,)).start()
-        time.sleep(.1)
+        ready = threading.Event()
+        threading.Thread(target=server, args=(self.evt, ready)).start()
+        ready.wait()
 
     def tearDown(self):
         self.evt.wait()


More information about the Python-3000-checkins mailing list