OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

I want to add retry logic and. refactor the code in the python socket connect code

  • Thread starter Thread starter Saurav K
  • Start date Start date
S

Saurav K

Guest
I have the below Python code which checks whether the ssh host is up or not:

Code:
`for hostname ,ipaddr in host_dict.items():       
            if tcp_conn.tcp_port_is_open(ipaddr, constants.TCP_PORT, constants.TCP_TIMEOUT) == True :
                print("host is Up")                
            else:
                print("Host is Down")`

I want to add retry logic which checks if the host is having some issue then it reconnects and checks whether it is up or not, the retry count will be 3.

I tried running the code and it works fine, but i want to add the retry logic in case the host is down or having some issues then retry should try to connect again with the host.
<p>I have the below Python code which checks whether the ssh host is up or not:</p>
<pre><code>`for hostname ,ipaddr in host_dict.items():
if tcp_conn.tcp_port_is_open(ipaddr, constants.TCP_PORT, constants.TCP_TIMEOUT) == True :
print("host is Up")
else:
print("Host is Down")`
</code></pre>
<p>I want to add retry logic which checks if the host is having some issue then it reconnects and checks whether it is up or not, the retry count will be 3.</p>
<p>I tried running the code and it works fine, but i want to add the retry logic in case the host is down or having some issues then retry should try to connect again with the host.</p>
 
Top