Thomas P Jakobsen
2010-01-19 22:18:59 UTC
# HG changeset patch
# User Thomas P Jakobsen <***@cs.au.dk>
# Date 1263939336 -3600
# Node ID 0b1e6cf3f57efe5a3b320897da636a6e2ebb2bdf
# Parent efa1983063d62a8115949a7e63d5ad4e5a23a791
Added option to avoid retrying to connect if socket is already in use.
In some situations it turns out to be more convenient to have VIFF
throw an exception rather than keep retrying to connect to a socket
with exponentially increasing delays. This is now possible using the
new command line parameter --no-socket-retry.
diff -r efa1983063d6 -r 0b1e6cf3f57e viff/runtime.py
--- a/viff/runtime.py Thu Jan 14 11:36:13 2010 +0100
+++ b/viff/runtime.py Tue Jan 19 23:15:36 2010 +0100
@@ -525,6 +525,10 @@
help="Collect and print profiling information.")
group.add_option("--track-memory", action="store_true",
help="Track memory usage over time.")
+ group.add_option("--no-socket-retry", action="store_false",
+ dest="socket_retry", default=True,
+ help="Fail rather than keep retrying to connect "
+ "if port is already in use.")
try:
# Using __import__ since we do not use the module, we are
@@ -1060,18 +1064,21 @@
connect = lambda host, port: reactor.connectTCP(host, port, factory)
port = players[id].port
- runtime.port = None
- delay = 2
- while runtime.port is None:
- # We keep trying to listen on the port, but with an
- # exponentially increasing delay between each attempt.
- try:
- runtime.port = listen(port)
- except CannotListenError, e:
- delay *= 1 + rand.random()
- print "Error listening on port %d: %s" % (port, e.socketError[1])
- print "Will try again in %d seconds" % delay
- time.sleep(delay)
+ if options and options.socket_retry:
+ runtime.port = None
+ delay = 2
+ while runtime.port is None:
+ # We keep trying to listen on the port, but with an
+ # exponentially increasing delay between each attempt.
+ try:
+ runtime.port = listen(port)
+ except CannotListenError, e:
+ delay *= 1 + rand.random()
+ print "Error listening on port %d: %s" % (port, e.socketError[1])
+ print "Will try again in %d seconds" % delay
+ time.sleep(delay)
+ else:
+ runtime.port = listen(port)
print "Listening on port %d" % port
for peer_id, player in players.iteritems():
# User Thomas P Jakobsen <***@cs.au.dk>
# Date 1263939336 -3600
# Node ID 0b1e6cf3f57efe5a3b320897da636a6e2ebb2bdf
# Parent efa1983063d62a8115949a7e63d5ad4e5a23a791
Added option to avoid retrying to connect if socket is already in use.
In some situations it turns out to be more convenient to have VIFF
throw an exception rather than keep retrying to connect to a socket
with exponentially increasing delays. This is now possible using the
new command line parameter --no-socket-retry.
diff -r efa1983063d6 -r 0b1e6cf3f57e viff/runtime.py
--- a/viff/runtime.py Thu Jan 14 11:36:13 2010 +0100
+++ b/viff/runtime.py Tue Jan 19 23:15:36 2010 +0100
@@ -525,6 +525,10 @@
help="Collect and print profiling information.")
group.add_option("--track-memory", action="store_true",
help="Track memory usage over time.")
+ group.add_option("--no-socket-retry", action="store_false",
+ dest="socket_retry", default=True,
+ help="Fail rather than keep retrying to connect "
+ "if port is already in use.")
try:
# Using __import__ since we do not use the module, we are
@@ -1060,18 +1064,21 @@
connect = lambda host, port: reactor.connectTCP(host, port, factory)
port = players[id].port
- runtime.port = None
- delay = 2
- while runtime.port is None:
- # We keep trying to listen on the port, but with an
- # exponentially increasing delay between each attempt.
- try:
- runtime.port = listen(port)
- except CannotListenError, e:
- delay *= 1 + rand.random()
- print "Error listening on port %d: %s" % (port, e.socketError[1])
- print "Will try again in %d seconds" % delay
- time.sleep(delay)
+ if options and options.socket_retry:
+ runtime.port = None
+ delay = 2
+ while runtime.port is None:
+ # We keep trying to listen on the port, but with an
+ # exponentially increasing delay between each attempt.
+ try:
+ runtime.port = listen(port)
+ except CannotListenError, e:
+ delay *= 1 + rand.random()
+ print "Error listening on port %d: %s" % (port, e.socketError[1])
+ print "Will try again in %d seconds" % delay
+ time.sleep(delay)
+ else:
+ runtime.port = listen(port)
print "Listening on port %d" % port
for peer_id, player in players.iteritems():