Advertisement
zamotivator

Untitled

Aug 5th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. commit 83da165365b7a6e9fda5313b4f44f4eddb6dd1c2
  2. Author: Oleg Tsarev <zabivator@gmail.com>
  3. Date: Sun Aug 5 21:37:56 2012 +0400
  4.  
  5. fix
  6.  
  7. diff --git a/tests/harness/runN.py b/tests/harness/runN.py
  8. index 7943161..d73144c 100755
  9. --- a/tests/harness/runN.py
  10. +++ b/tests/harness/runN.py
  11. @@ -9,6 +9,7 @@ import sys
  12. import time
  13. import os
  14. import string
  15. +import itertools
  16.  
  17. # Just for sanity. You could probably run more if you wanted to
  18. MAX_SUPPORTED_INSTANCES = 20
  19. @@ -193,22 +194,79 @@ def shutdown(p):
  20. p.terminate()
  21.  
  22. def check_pidfile():
  23. + RETRY_COUNT = int(os.environ.get('SCIDB_KILL_TIMEOUT', 5))
  24. if (os.path.exists(pidfile)):
  25. - f = open(pidfile, 'r')
  26. - for line in f:
  27. - pid = line.strip()
  28. - procfile = "/proc/" + pid + "/stat"
  29. - if (os.path.exists(procfile)):
  30. - f1 = open(procfile, 'r')
  31. - progname = string.split(f1.readline())[1]
  32. - f1.close()
  33. - if ( progname == "(scidb)" ) or ( dlaRunner != '0' and progname == "("+dlaRunner+")" ):
  34. - print "NOTE: killing old scidb instance at PID " + pid
  35. - subprocess.Popen(["kill", "-SIGTERM", pid], cwd=".").wait()
  36. - time.sleep(1)
  37. - subprocess.Popen(["kill", "-9", pid], cwd=".").wait()
  38. - while (os.path.exists(procfile)):
  39. - time.sleep(1)
  40. + def get_prog_name(pid):
  41. + result = None
  42. + # proc file name
  43. + pfn = "/proc/%s/stat" % pid
  44. + if os.path.exists(pfn):
  45. + # proc file
  46. + with open(pfn, 'r') as pf:
  47. + result = string.split(pf.readline())[1]
  48. + pf.close()
  49. + return result
  50. +
  51. + def is_actual_pid(pid):
  52. + prog_name = get_prog_name(pid)
  53. + return prog_name == "(scidb)" or (dlaRunner != '0' and prog_name== "(%s)" % dlaRunner)
  54. +
  55. + watchdog_list = filter(is_actual_pid, map(string.strip, open(pidfile, 'r')))
  56. +
  57. + def get_children(pid):
  58. + ps = subprocess.Popen(["ps", "-o", "pid", "--no-headers", "--ppid", pid], stdout=subprocess.PIPE, cwd=".")
  59. + ps.wait()
  60. + result = []
  61. + for item in ps.communicate():
  62. + if not item is None:
  63. + result.append(item.strip())
  64. + print "children for '%s' are [%s]" % (pid, ",".join(result))
  65. + return result
  66. +
  67. + child_list = []
  68. + for item_list in map(get_children, watchdog_list):
  69. + for item in item_list:
  70. + child_list.append(item)
  71. +
  72. + def kill(pid_list, signal):
  73. + killer_list = []
  74. + for pid in pid_list:
  75. + print "NOTE: killing old scidb instance at PID %s by %s signal" % (pid, signal)
  76. + killer_list.append(subprocess.Popen(["kill", signal, pid], cwd="."))
  77. +
  78. + time.sleep(1)
  79. +
  80. + for killer in killer_list:
  81. + killer.wait()
  82. +
  83. + kill(watchdog_list, "-SIGTERM")
  84. + watchdog_list = filter(is_actual_pid, watchdog_list)
  85. + kill(watchdog_list, "-9")
  86. + watchdog_list = filter(is_actual_pid, watchdog_list)
  87. +
  88. + retry = RETRY_COUNT
  89. + while retry > 0 and len(watchdog_list):
  90. + print "Waiting while SciDB processes are completing, pid list [%s]" % (",".join(watchdog_list))
  91. + time.sleep(1)
  92. + watchdog_list = filter(is_actual_pid, watchdog_list)
  93. + retry -= 1
  94. +
  95. + if len(watchdog_list):
  96. + sys.stderr.write('Some SciDB processes still runing: [%s]\n' % ",".join(watchdog_list))
  97. + exit(-1)
  98. +
  99. + child_list = filter(is_actual_pid, child_list)
  100. +
  101. + retry = RETRY_COUNT
  102. + while retry > 0 and len(child_list):
  103. + print "Waiting while SciDB child processes are completing, pid list [%s]" % (",".join(child_list))
  104. + time.sleep(1)
  105. + child_list = filter(is_actual_pid, child_list)
  106. + retry -= 1
  107. +
  108. + if len(child_list):
  109. + sys.stderr.write("Some SciDB schild processes still runing: [%s]\n" % ",".join(watchdog_list))
  110. + exit(-1)
  111.  
  112. def savepids(master_pid, instancePids):
  113. subprocess.Popen(["rm", "-f", pidfile], cwd=".").wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement