[BangPypers] Background ping - check for server availability
Nikunj.Badjatya at emc.com
Nikunj.Badjatya at emc.com
Thu Dec 29 12:53:54 CET 2011
Hi,
I want to check the availability of the server ( in the sense ) by continuously pinging it in intervals of 30 seconds.
I am using Python2.7 on windows platform.
I wrote the following snippet. It works fine but it opens a windows cmd prompt everytime it is reaching subprocess.call()
{{{
import subprocess
import time
def checkserveravail(ip):
while True:
pingret = subprocess.call('ping {0} -n 1'.format(esxname))
if pingret == 0:
time.sleep(30)
continue
else:
print("The server {0} is not reacheable. Please check network connectivity".format(ip))
checkserveravail('xx.xx.xx.xx')
}}}
This snippet will be a part of larger program. Where a thread will be doing this job of checking server recheability.
I do not want that cmd prompt windows to open everytime and just want this job to happen in background.
I also do not want to import any external module like ping, which will unnecessarily increase the dependencies in my programs.
Any clues?
Thanks,
Nikunj
7 Switch off as you go | qRecycle always | P Save Paper - Save Trees | Go Green
More information about the BangPypers
mailing list