terminating an inactive process

E

Earl Eiland

I'm running a PyWin program that executes another program using
subprocess.Popen(). Unfortunately, this other program isn't well
behaved, and frequently terminates without terminating its process.
After this happens enough times, all my memory is tied up, and the
machine crashes.

Using subprocess.poll(), I can keep my program from hanging, by timing
out the process, and starting anew. This still leaves the previous
process hogging memory. How do I kill the old process in Windows?

Earl
 
F

fred.dixon

i use this to open/close netscape as it also doesnt like to close all
the time. its a WMI script but easiely edited.

check out script-o-matic from ms-downloads , it outputs python code as
well as others.
######################################################################
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Process",,48)
For Each objItem in colItems
strProcess = Ucase(objItem.Name)
If strProcess = "NETSCP.EXE" Then
objItem.Terminate()
End If
Next
'---------------------
MyVar = MsgBox ("Do you want to start Netscape Mail and News " &
chr(13) & chr(13) & "Any Zombie processes have been exorcised from the
machine already." & chr(13) & chr(13) , 308, "Warning!")
Set objWMIService = Nothing
Set colItems = Nothing
If MyVar = 7 Then
Wscript.Quit
Else
sExecStr = "C:\Program Files\Netscape\Netscape\Netscp.exe -mail"
Dim oShell, obj
Set oShell = WScript.CreateObject ("WSCript.shell")
Set obj = oShell.exec(sExecStr)
Set oShell = Nothing
Set obj = Nothing
End If

'--------------------------------
MyVar = MsgBox ("Click to close Netscape")
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_Process",,48)
For Each objItem in colItems
strProcess = Ucase(objItem.Name)
If strProcess = "NETSCP.EXE" Then
objItem.Terminate()
End If
Next
Set objWMIService = Nothing
Set colItems = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top