本文整理汇总了Python中win32con.PROCESS_TERMINATE属性的典型用法代码示例。如果您正苦于以下问题:Python win32con.PROCESS_TERMINATE属性的具体用法?Python win32con.PROCESS_TERMINATE怎么用?Python win32con.PROCESS_TERMINATE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类win32con
的用法示例。
在下文中一共展示了win32con.PROCESS_TERMINATE属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import PROCESS_TERMINATE [as 别名]
def __init__(self, *args, **kwargs):
kwargs = dict(_Popen_defaults + kwargs.items())
if 'creationflagsmerge' in kwargs:
kwargs['creationflags'] = (
kwargs.get('creationflags', 0) | kwargs['creationflagsmerge'])
del kwargs['creationflagsmerge']
for f in ['stdout', 'stderr']:
if kwargs[f] is SINK:
kwargs[f] = create_sink()
# super() does some magic that makes **kwargs not work, so just call
# our super-constructor directly
subprocess.Popen.__init__(self, *args, **kwargs)
_CHILD_PROCS.append(self)
if mswindows and _kill_children_on_death:
handle = windll.kernel32.OpenProcess(
win32con.SYNCHRONIZE | win32con.PROCESS_SET_QUOTA | win32con.PROCESS_TERMINATE, 0, self.pid)
if win32job.AssignProcessToJobObject(_chJob, handle) == 0:
raise WinError()
# TODO(infinity0): perhaps replace Popen.std* with wrapped file objects
# that don't buffer readlines() et. al. Currently one must avoid these and
# use while/readline(); see man page for "python -u" for more details.
示例2: SvcDoRun
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import PROCESS_TERMINATE [as 别名]
def SvcDoRun(self):
import servicemanager
servicemanager.LogInfoMsg(self._svc_name_ + " Start Requested")
try:
hJob = win32job.CreateJobObject(None, "")
extended_info = win32job.QueryInformationJobObject(hJob, win32job.JobObjectExtendedLimitInformation)
extended_info['BasicLimitInformation']['LimitFlags'] = win32job.JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE
win32job.SetInformationJobObject(hJob, win32job.JobObjectExtendedLimitInformation, extended_info)
command = "resilient-circuits.exe run " + self._resilient_args_
command_args = shlex.split(command)
self.process_handle = subprocess.Popen(command_args)
# Convert process id to process handle:
perms = win32con.PROCESS_TERMINATE | win32con.PROCESS_SET_QUOTA
hProcess = win32api.OpenProcess(perms, False, self.process_handle.pid)
win32job.AssignProcessToJobObject(hJob, hProcess)
except:
servicemanager.LogErrorMsg(self._svc_name_ + " failed to launch resilient-circuits.exe")
raise
servicemanager.LogInfoMsg(self._svc_name_ + " Started")
while self.isAlive:
if self.process_handle.poll() != None:
self.SvcStop()
win32api.SleepEx(10000, True)
示例3: killProcName
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import PROCESS_TERMINATE [as 别名]
def killProcName(procname):
# Change suggested by Dan Knierim, who found that this performed a
# "refresh", allowing us to kill processes created since this was run
# for the first time.
try:
win32pdhutil.GetPerformanceAttributes('Process','ID Process',procname)
except:
pass
pids = win32pdhutil.FindPerformanceAttributesByName(procname)
# If _my_ pid in there, remove it!
try:
pids.remove(win32api.GetCurrentProcessId())
except ValueError:
pass
if len(pids)==0:
result = "Can't find %s" % procname
elif len(pids)>1:
result = "Found too many %s's - pids=`%s`" % (procname,pids)
else:
handle = win32api.OpenProcess(win32con.PROCESS_TERMINATE, 0,pids[0])
win32api.TerminateProcess(handle,0)
win32api.CloseHandle(handle)
result = ""
return result
示例4: kill
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import PROCESS_TERMINATE [as 别名]
def kill(self):
handle = win32api.OpenProcess(
win32con.PROCESS_VM_READ | win32con.PROCESS_TERMINATE, pywintypes.FALSE, self.childpid)
win32process.TerminateProcess(handle, 3)
示例5: kill_process
# 需要导入模块: import win32con [as 别名]
# 或者: from win32con import PROCESS_TERMINATE [as 别名]
def kill_process(name):
for pid in win32process.EnumProcesses():
# do try not to kill yourself
if pid == win32api.GetCurrentProcessId():
continue
try:
p = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION
| win32con.PROCESS_VM_READ
| win32con.PROCESS_TERMINATE,
False, pid)
except:
continue
if not p:
continue
try:
hl = win32process.EnumProcessModules(p)
except:
win32api.CloseHandle(p)
continue
h = hl[0]
pname = win32process.GetModuleFileNameEx(p, h)
root, pname = os.path.split(pname)
#print name, pname
if compare(name, pname):
#print "KILL", pname
win32api.TerminateProcess(p, 0)
win32api.CloseHandle(p)
return True
win32api.CloseHandle(p)
return False