[python-win32] terminateprocess, getprocessid and compiling trunk on win32

benjamin deboute deboute at gmail.com
Wed May 16 15:09:49 CEST 2007


Hi Mark,

On 5/16/07, Mark Hammond <mhammond at skippinet.com.au> wrote:
> These appear to be a reposts of the message you sent on May 11, which I also
> answered on that same day (notwithstanding time zones!)
>

Sorry about that, but actually they were sent before and never managed
to appear on the list until now :\

I encountered a strange problem when trying to post this message the
other week, from another email address than the one i'm using right
now. Those two emails where sent 09/05 and 10/05 and never appeared
before just now, but as a matter of fact i did saw two posts from
other people on the list which had as enveloppe-from
"python-win32-bounces+benjamin.d=sparx.com at python.org". I alerted
python.org mailing list admin on this really strange postfix behaviour
and reposted my mail using another email addy and this time it
actually went through.
Quite voodoo story, and as everything voodoo, it now has its own
zombies with those mails that have been raised from the dead



Anyway, sorry for not having answered before but i was slightly overworked :\

>>i'm currently building a multi-platform renderfarm application, and
>> would need to use GetProcessId to circumvant problems i encounter when
>> i try to kill processes on win32
>>
>> IE: i can't kill with TerminateProcess a process i spawned with
>> CreateProcess (getting a Acess Denied error), but i can kill it using
>> this chunk of aspn'd code
>>
>> PROCESS_TERMINATE = 1
>> handle = win32api.OpenProcess(PROCESS_TERMINATE, False, pid)
>> win32api.TerminateProcess(handle, -1)
>> win32api.CloseHandle(handle)


>But doesn't CreateProcess also return the PID to you, meaning you can safely
>use the code above?  If the 2 processes are running as the same user, I'm
>surprised it fails.


So, as i was telling, when i use createprocess i can't find the PID

In [1]: import win32process
In [2]: s = 'd:\\APPLIS\\cygwin\\bin\\ping.exe -t embrun'
In [3]: win32process.CreateProcess(None, s,None, None, 1, 0,
None,None, win32process.STARTUPINFO())
Out[3]: (<PyHANDLE:96>, <PyHANDLE:156>, 1316, 1528)

and the ping.exe process is listed with a PID of 1402 in windows' tasks manager


I have checked msdn and have seen the function that is called via
win32.process.CreateProcess is stated to return a ProcessInformation
structure, that contains the process ProcessId as its 3rd entry

http://msdn2.microsoft.com/en-us/library/ms684873.aspx

So in my case, the process id returned would be 1316

In order to be sure i invoked

PROCESS_TERMINATE = 1
handle = win32api.OpenProcess(PROCESS_TERMINATE, False, 1316)
win32api.TerminateProcess(handle, -1)
win32api.CloseHandle(handle)

A quick glance in my task manager window showed me that the ping
process was still running

I then tried the same chuck of code with a PID of 1402, and the ping
process this time disapeared from the task manager

For your info, i'm on win2k






For the compilation problems

>> Warning - can't find an installed platform SDK
>> > error: The .NET Framework SDK needs to be installed before building
>> > extensions for Python.
>> >
>> > After several .net installs, i still got this error : \
> After installing the Platform SDK (or .NET SDK), you still got the exact
> error above?  It might be worth looking at the source code to see why it
> fails to be detected.
> > i also tried (and failed) compiling it on visual studio, cygwin+mingw,
> These day, setup.py is the only way that is known to work (well - sometimes :)

The .NET error message has been resolved by reading more carefully and
realizing that i needed a computer with visual platform sdk installed.
Don't know why it incorrectly states .NET as being seeked, as the
string *NET* does not exist in setup.py so i suppose it's windows
internals that are at fault

As i progressed, this error has been raised 'Can't find a version in Windows.h'
Been crudely taken care of with finding the hexa value in windows.h
and assigning it to a variable in setup.py

Then i got a linking problem with pywintypes, Link reported that it
couldn't find pywintypes.lib

i searched around and found that pywintypes is a lib included in
pywin32, i found it strange that pywin32 couldn't be build if pywin32
wasn't installed in the system, but i shrugged the shrug of
HeWhoIsCompilingOnWindows and copied pywintypes.lib shamelessly at the
root of my source directory



Then pywin32 compiled some more and crashed on this

C:\APPLIS\Microsoft Visual Studio .NET 2003\Vc7\bin\link.exe /DLL
/nologo /INCREMENTAL:NO /LIBPATH:C:\Python24\libs
/LIBPATH:C:\Python24\PCBuild /LIBPATH:build\temp.win32-2.4\Release
/EXPORT:initwin32pdh
build\temp.win32-2.4\Release\win32\src\win32pdhmodule.obj
/OUT:build\lib.win32-2.4\win32\win32pdh.pyd
/IMPLIB:build\temp.win32-2.4\Release\win32\src\win32pdh.lib
/MACHINE:ix86 /BASE:0x1eb30000 /DEBUG
/PDB:build\temp.win32-2.4\Release\win32pdh.pdb
   Creating library
build\temp.win32-2.4\Release\win32\src\win32pdh.lib and object
build\temp.win32-2.4\Release\win32\src\win32pdh.exp
win32pdhmodule.obj : error LNK2019: external symbol unresolved
"__declspec(dllimport) struct _object * __cdecl
PyWinLong_FromHANDLE(void *)"
(__imp_?PyWinLong_FromHANDLE@@YAPAU_object@@PAX at Z) referenced in
function "struct _object * __cdecl PyAddCounter(struct _object
*,struct _object *)" (?PyAddCounter@@YAPAU_object@@PAU1 at 0@Z)
build\lib.win32-2.4\win32\win32pdh.pyd : fatal error LNK1120: 1
external unresolved

As it states that PyWinLong_FromHandle is not declared in pywintypes i
verified that i had the latest relased version of pywin32 (it was) and
grepped the lib for PywinLong
No match was found for it



This is where i stopped yesterday, i hope the gritty details will help
you understand the issue. If you need specific info that i did not
include, please ask

Regards,
ben


More information about the Python-win32 mailing list