[python-win32] win32process open-terminate loop cripples OS
Tom_RobbinsMilne at swissre.com
Tom_RobbinsMilne at swissre.com
Mon Mar 20 16:32:40 CET 2006
David,
Maybe I'm missing something, but doesn't XP take awhile to launch and kill
Notepad?
Does it work a bit better if you launch a process every 10 seconds?
Thanks,
Tom
"David S." <david128 at receptec.net>
Sent by: python-win32-bounces at python.org
03/20/2006 09:42 AM
To
python-win32 at python.org
cc
Subject
[python-win32] win32process open-terminate loop cripples OS
Hello,
I decided to attempt to use python's win32 extensions as a method to
monitor and control process for my python application. It's working
well in the short term, but, as this app is intended to be very
low-maintenance, and probably high-uptimes without restarting, I want to
put it to the test. I set a loop similar to below to run every second
for the weekend. It wasn't very pretty. I didn't get any process
information (couldn't - system was /almost/ unresponsive) - the most i
could do was alt-tab around, though it wouldn't paint the window, move
the mouse pointer and turn the num lock light on and off. Can anyone
provide some guidance or perhaps point out a problem in my code?
For what it's worth, I think I can poll process /ad infinitum/ without
any lockups.
Thank you,
-David S.
---------------------------------------------------------------------------
def weekendprocesstest():
print 1
Processes.StartProcess("notepad")
print 2
Processes.KillName("notepad")
print 3
---and the functions....
def StartProcess(self, RunCmd):
#not going to bother with win32 for this
#output=os.System(RunCmd).read()
StartupInfo = win32process.STARTUPINFO()
win32process.CreateProcess(
None, # program
RunCmd, # command line
None, # process security attributes
None, # thread attributes
1, # inherit handles, or USESTDHANDLES won't work.
# creation flags. Don't access the console.
0, # Don't need anything here.
# If you're in a GUI app, you should use
# CREATE_NEW_CONSOLE here, or any subprocesses
# might fall victim to the problem described in:
# KB article: Q156755, cmd.exe requires
# an NT console in order to perform redirection..
None, # new environment
None, # new directory
StartupInfo)
self.ProcessTableRefresh()
def KillName(self, matchstring):
#get PIDS that have the supplied substring
self.ProcessTableRefresh()
ProcessList=self.GetProcessList()
for process in ProcessList:
if process[2].lower().find(matchstring.lower())!=-1:
win32process.TerminateProcess(process[0],0)
self.ProcessTableRefresh()
def ProcessTableRefresh(self):
processes = win32process.EnumProcesses()
pnamepidlist=list()
for pid in processes:
try:
handle =
win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS,False, pid)
exe = win32process.GetModuleFileNameEx(handle, 0)
pnamepidlist.append((handle, pid, exe))
except:
pass
self.lProcessTable.acquire()
self.ProcessList=pnamepidlist
self.ProcessTableAge=0
self.lProcessTable.release()
_______________________________________________
Python-win32 mailing list
Python-win32 at python.org
http://mail.python.org/mailman/listinfo/python-win32
This e-mail, including attachments, is intended for the person(s) or company named and may contain confidential and/or legally privileged information. Unauthorized disclosure, copying or use of this information may be unlawful and is prohibited. If you are not the intended recipient, please delete this message and notify the sender
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20060320/a38e69f9/attachment.htm
More information about the Python-win32
mailing list