-
-
-xmpp_msg_lastmsg = ""
-action_by = ""
-xmpp_firstmsg = True
-
-def sendXmppMsg(recipients, msg, resource = "torwaechter", addtimestamp = True, noofflinemsg = False):
- if type(recipients) == types.ListType:
- recipients = " ".join(recipients)
- if type(recipients) == types.UnicodeType:
- recipients = recipients.decode("utf-8")
- if type(recipients) != types.StringType:
- raise Exception("list of recipients in unknown format, can't send message")
- if recipients == "" or msg == "":
- return
-
- sendxmpp_cmd = "sendxmpp -u realrauminfo -p 5SPjTdub -j jabber.tittelbach.at -t "
- if resource:
- sendxmpp_cmd += "-r %s " % resource
- if noofflinemsg:
- sendxmpp_cmd += "--headline "
- sendxmpp_cmd += recipients
-
- if addtimestamp:
- msg += time.strftime(" (%Y-%m-%d %T)")
+def popenTimeout1(cmd, pinput, returncode_ok=[0], ptimeout = 20.0, pcheckint = 0.25):
+ logging.debug("popenTimeout1: starting: " + cmd)
+ try:
+ sppoo = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=True)
+ sppoo.communicate(input=pinput)
+ timeout_counter=ptimeout
+ while timeout_counter > 0:
+ time.sleep(pcheckint)
+ timeout_counter -= pcheckint
+ if not sppoo.poll() is None:
+ logging.debug("popenTimeout2: subprocess %d finished, returncode: %d" % (sppoo.pid,sppoo.returncode))
+ return (sppoo.returncode in returncode_ok)
+ #timeout reached
+ logging.error("popenTimeout1: subprocess took too long (>%fs), sending SIGTERM to pid %d" % (ptimeout,sppoo.pid))
+ if sys.hexversion >= 0x020600F0:
+ sppoo.terminate()
+ else:
+ subprocess.call(["kill",str(sppoo.pid)])
+ time.sleep(1.0)
+ if sppoo.poll() is None:
+ logging.error("popenTimeout1: subprocess still alive, sending SIGKILL to pid %d" % (sppoo.pid))
+ if sys.hexversion >= 0x020600F0:
+ sppoo.kill()
+ else:
+ subprocess.call(["kill","-9",str(sppoo.pid)])
+ return False
+ except Exception, e:
+ logging.error("popenTimeout1: "+str(e))
+ return False