def _pingThread(host, port, pingEvent, dummy): """ Ping the node defined by the given host name/port number. host: Hostname (string). port: Port number (integer). pingEvent: Used to communicate back to calling thread if a connection to the specified host could be established (threading.Event). Returns: Void. """ import httplib, thread try: httpObj = httplib.HTTPConnection(host, port) httpObj.request("GET", "/STATUS") respObj = httpObj.getresponse() respObj.read() pingEvent.set() try: thread.exit() except: pass except Exception, e: try: thread.exit() except: pass def ngasPingHost(host, port, timeOut = 0.5): """ Pings a specific host/port to check if a connection can be opened. This is done by issuing a STATUS Command to the node. Will max. wait for a response for the specified timeout. host: NGAS host to ping (string). port: Port on NGAS host to ping (integer). timeOut: Timeout in seconds (float). Returns: 1 in case the NGAS Node could be accessed within the given timeout, otherwise 0 is returned (integer/0|1). """ pingEvent = None pingThread = None try: pingEvent = threading.Event() args = (host, port, pingEvent, None) pingThread = threading.Thread(None, _pingThread, "PING-THREAD", args) print ">>>>> pingThread=",pingThread print ">>>>> dir(pingThread)=",dir(pingThread) print ">>>>> dir(pingThread._Thread__stop)=",\ dir(pingThread._Thread__stop) pingThread.setDaemon(1) pingThread.start() pingEvent.wait(timeOut) if (pingEvent.isSet()): stat = 1 else: stat = 0 del pingEvent try: pingThread.exit() except Exception, e: print ">>>>> pingThread.exit()/e=",str(e) del pingThread return stat except: if (pingEvent): del pingEvent if (pingThread): pingThread.exit() del pingThread