network programming without goto

kent sin kentsin at
Thu Nov 25 15:53:53 CET 2004

Please help:

I was really blocked here. without goto I really do
not known how to do it.

The problem is to use PyZ3950 to consult a lists of
hosts and for each of them to search for a list of
targets. Since the network is undetermined, there were
always some exceptions: I would like to allow it to
retry for 3 times. Moreover, during the query process,
the conn will timeout (set by the remote server).
Reconnect is preferred before fail the current search,
but the reconnect may fail even if the first try is

for host in hostlist:
        # sometimes the host may fail
        conn =zoom.Connecton(host.ip, host.port)
        continue  # Next host? But How to give it some
chance? 3 times?
    reconnect = 0
    for t in targets:
        # ?
        if reconnect:
           # if conn timeout, reconnect
               # Fail??? 3 chances rules here?
               conn = zoom.Connection(host.ip,
               # ? Where should I go?
        q = buildquery(t)
        try: # Hay, any things can be broken
             # and after some iteration, conn should
             r =
             reconnect = 1
             #??? how to retry this t?

More information about the Python-list mailing list