killProcByPID.py

Go to the documentation of this file.
00001 __copyright__ = """\
00002 (c). Copyright 1990-2008, Vyper Logix Corp., All Rights Reserved.
00003 
00004 Published under Creative Commons License 
00005 (http://creativecommons.org/licenses/by-nc/3.0/) 
00006 restricted to non-commercial educational use only., 
00007 
00008 See also: http://www.VyperLogix.com and http://www.pypi.info for details.
00009 
00010 THE AUTHOR VYPER LOGIX CORP DISCLAIMS ALL WARRANTIES WITH REGARD TO
00011 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
00012 FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
00013 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
00014 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00015 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
00016 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
00017 
00018 USE AT YOUR OWN RISK.
00019 """
00020 
00021 import os, sys
00022 from vyperlogix import misc
00023 
00024 def killProcByPID(pid,isVerbose=False):
00025     info_string = ''
00026     if (isVerbose):
00027         print >>sys.stderr, '(%s) :: sys.platform is "%s".' % (misc.funcName(),sys.platform)
00028     if (sys.platform == 'win32'):
00029         def kill(pid):
00030             info_string = ''
00031             from vyperlogix.win import WinProcesses
00032             p = WinProcesses.WinProcesses()
00033             proc_handle = p.openProcessTerminateForPID(pid)
00034             if (isVerbose):
00035                 print >>sys.stderr, '(%s) :: proc_handle is "%s".' % (misc.funcName(),proc_handle)
00036             if (proc_handle):
00037                 try:
00038                     import win32api
00039                     win32api.TerminateProcess(proc_handle, -1)
00040                 except Exception, details:
00041                     from vyperlogix.misc import _utils
00042                     info_string += _utils.formattedException(details=details)
00043                     try:
00044                         import ctypes
00045                         ctypes.windll.kernel32.TerminateProcess(proc_handle, -1)
00046                     except Exception, details:
00047                         from vyperlogix.misc import _utils
00048                         info_string += _utils.formattedException(details=details)
00049                         print >>sys.stderr, 'ERROR: Cannot Kill the process with pid of %s due to a system error.' % (pid)
00050                         print >>sys.stderr, info_string
00051                 finally:
00052                     p.closeProcessHandle(proc_handle)
00053         if (isVerbose):
00054             print >>sys.stderr, '(%s) :: kill(%d).' % (misc.funcName(),pid)
00055         kill(pid)
00056     else:
00057         try:
00058             os.kill(pid)
00059         except Exception, details:
00060             from vyperlogix.misc import _utils
00061             info_string += _utils.formattedException(details=details)
00062             print >>sys.stderr, 'ERROR: Cannot kill the process !'
00063             print >>sys.stderr, info_string
00064     if (isVerbose):
00065         print >>sys.stderr, '(%s) :: info_string is "%s".' % (misc.funcName(),info_string)
00066 
00067 if __name__ == "__main__":
00068     import sys
00069     print >>sys.stdout, __copyright__
00070     print >>sys.stderr, __copyright__
00071 
00072 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...