CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions
watchdog Namespace Reference

Classes

class  Timeout
 

Functions

def alarm_handler (signum, frame)
 
def launch (args)
 
def log (s)
 
def main (args)
 

Function Documentation

def watchdog.alarm_handler (   signum,
  frame 
)

Definition at line 15 of file watchdog.py.

15 def alarm_handler(signum, frame):
16  if signum != 14: return
17  raise Timeout("Timeout reached.")
18 
19 signal.signal(signal.SIGALRM, alarm_handler)
20 
def alarm_handler(signum, frame)
Definition: watchdog.py:15
def watchdog.launch (   args)

Definition at line 25 of file watchdog.py.

References log(), and harvestTrackValidationPlots.str.

Referenced by main().

25 def launch(args):
26  fd, wd = os.pipe()
27 
28  def preexec():
29  os.close(fd)
30 
31  env = os.environ
32  env["WATCHDOG_FD"] = str(wd)
33 
34  p = subprocess.Popen(args.pargs, preexec_fn=preexec, stdin=stdin_, stdout=stdout_)
35  os.close(wd)
36 
37  while True:
38  try:
39  signal.alarm(args.t)
40  ch = os.read(fd, 1024)
41  signal.alarm(0)
42 
43  if not ch:
44  os.close(fd)
45  return False, p.wait() # normal exit
46 
47  log("Received: %s, timer reset." % repr(ch))
48 
49  except Timeout as t:
50  signal.alarm(0)
51 
52  log("Timeout reached, taking action.")
53 
54  if p.poll() is None:
55  p.send_signal(args.action)
56 
57  os.close(fd)
58  return True, p.wait()
59 
60  for p in open_procs_:
61  if p.poll() is None:
62  p.send_signal(sig)
63 
def log(s)
Definition: watchdog.py:21
def launch(args)
Definition: watchdog.py:25
def watchdog.log (   s)

Definition at line 21 of file watchdog.py.

Referenced by launch(), and main().

21 def log(s):
22  sys.stderr.write("watchdog: " + s + "\n");
23  sys.stderr.flush()
24 
def log(s)
Definition: watchdog.py:21
def watchdog.main (   args)

Definition at line 64 of file watchdog.py.

References launch(), and log().

64 def main(args):
65  while True:
66  killed, ret = launch(args)
67  log("Program exitted, killed: %s, code: %d." % (killed, ret, ))
68 
69  if killed and args.restart:
70  log("Restarting.")
71  continue
72 
73  break
74 
75 
def log(s)
Definition: watchdog.py:21
def main(args)
Definition: watchdog.py:64
def launch(args)
Definition: watchdog.py:25