#! /usr/bin/env python

#  _________________________________________________________________________
#
#  Coopr: A COmmon Optimization Python Repository
#  Copyright (c) 2010 Sandia Corporation.
#  This software is distributed under the BSD License.
#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
#  the U.S. Government retains certain rights in this software.
#  For more information, see the FAST README.txt file.
#  _________________________________________________________________________

# a simple utility to kill a set of pyro_mip_servers, specified through
# a file containing a list of the corresponding PIDs - presumably 
# generated through the sibling launch_pyro_mip_servers script.

import os
import sys
import string
import os
import signal

if len(sys.argv) > 2:
   print "***Incorrect invocation - use: kill_pyro_mip_servers pid-filename"
   sys.exit(1)

pid_filename = "pyro_mip_servers.pids"
if len(sys.argv) == 2:
   pid_filename = sys.argv[1]

print "Killing pyro mip servers specified in file="+pid_filename

pid_file = open(pid_filename, "r")
for line in pid_file.readlines():
   pid = eval(string.strip(line))
   print "KILLING PID="+str(pid)
   os.kill(pid, signal.SIGTERM)
pid_file.close()

