[pypy-svn] r47077 - pypy/dist/pypy/translator/js/examples/bnb

arigo at codespeak.net arigo at codespeak.net
Mon Oct 1 19:35:50 CEST 2007


Author: arigo
Date: Mon Oct  1 19:35:48 2007
New Revision: 47077

Modified:
   pypy/dist/pypy/translator/js/examples/bnb/bnb.py
Log:
Compute the port lazily as a quick workaround for the fact that this
logic hangs forever if there is a non-responsive process listening
on localhost:8000.  Mostly untested, sorry if I break something.


Modified: pypy/dist/pypy/translator/js/examples/bnb/bnb.py
==============================================================================
--- pypy/dist/pypy/translator/js/examples/bnb/bnb.py	(original)
+++ pypy/dist/pypy/translator/js/examples/bnb/bnb.py	Mon Oct  1 19:35:48 2007
@@ -70,15 +70,22 @@
     _spriteManagers = {}
 
     host = 'localhost'
-    try:
-        port = re.findall('value=".*"', urllib.urlopen('http://%s:8000' % host).read())[0]
-        port = int(port[7:-1])
-    except IOError:
-        log("ERROR: Can't connect to BnB server on %s:8000" % host)
-#        sys.exit()
-    except IndexError:
-        log("ERROR: Connected to BnB server but unable to detect a running game")
-#        sys.exit()
+
+    def getport(self):
+        if hasattr(self, '_port'):
+            return self._port
+        try:
+            port = re.findall('value=".*"', urllib.urlopen('http://%s:8000' % host).read())[0]
+            port = int(port[7:-1])
+        except IOError:
+            log("ERROR: Can't connect to BnB server on %s:8000" % host)
+            raise IOError
+        except IndexError:
+            log("ERROR: Connected to BnB server but unable to detect a running game")
+            raise IOError
+        self._port = port
+        return port
+    port = property(getport)
 
     #def _close(self, sessionid):
     #    if sessionid in self._serverMessage:



More information about the Pypy-commit mailing list