Thomas P Jakobsen <[email protected]> writes: > # HG changeset patch > # User Thomas P Jakobsen <[email protected]> > # 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.
Sure, that's a nice idea.
> 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:
You should be able to achieve the same by inserting:
if options and options.no_socket_retry:
raise
(I renamed the destination for the flag)
> - 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)
--
Martin Geisler
VIFF (Virtual Ideal Functionality Framework) brings easy and efficient
SMPC (Secure Multiparty Computation) to Python. See: http://viff.dk/.
pgpsw8TQepyzV.pgp
Description: PGP signature
_______________________________________________ viff-patches mailing list [email protected] http://lists.viff.dk/listinfo.cgi/viff-patches-viff.dk
