Closed GoogleCodeExporter closed 9 years ago
I don't have time to look into this now but a quick google search suggests this
a problem common to other projects as well.
Original comment by g.rodola
on 4 Jan 2013 at 4:55
I checked _psutil_mswindows.pyd with Dependency Walker. It's looking for the
following functions in Kernel32.dll:
K32EnumProcesses
K32GetMappedFileNameA
K32GetProcessImageFileNameA
K32GetProcessMemoryInfo
These were added to Kernel32 in NT 6.1+, such as Windows 7. If you're using XP
(NT 5.1) or Vista (NT 6.0), they're instead in Psapi.dll, without the K32
prefix. The following blog discusses a workaround to bypass the K32
macros by setting PSAPI_VERSION=1:
http://blogs.msdn.com/b/vcblog/archive/2009/08/27/windows-sdk-v7-0-v7-0a-incompa
tibility-workaround.aspx
For now, in Vista I used Visual Studio 2010 Express to build from source.
Original comment by eryksun
on 19 Mar 2013 at 8:42
Thanks for the insight.
Can someone please try the patch in attachment? I'm still unable to reproduce
this issue.
Original comment by g.rodola
on 19 Mar 2013 at 10:37
Attachments:
Thanks for the insight.
Can someone please try the patch in attachment? I'm still unable to reproduce
this issue.
Original comment by g.rodola
on 19 Mar 2013 at 10:37
Attachments:
It's already conditionally defined in Psapi.h:
#ifndef PSAPI_VERSION
#if (NTDDI_VERSION >= NTDDI_WIN7)
#define PSAPI_VERSION 2
#else
#define PSAPI_VERSION 1
#endif
#endif
I can successfully build from source on Vista. The issue is with the version
distributed in the downloads. You have the option to force PSAPI_VERSION=1 when
building so as to also support XP and Vista in a single build. This incurs a
performance penalty because the linker uses Psapi.dll instead of the K32
functions in kernel32.dll. Instead you could instead distribute separate
versions for XP/Vista and Windows 7+.
Original comment by eryksun
on 22 Mar 2013 at 12:53
You mean performance penalty when compiling?
Distributing different installers for XP/7+ is a non option since we're already
providing 8 installers for Windows.
Original comment by g.rodola
on 22 Mar 2013 at 6:16
The old Psapi.dll still exists in 7+. They've just reimplemented it in
kernel32.dll for performance. You could test linking to kernel32.dll vs
psapi.dll, but I doubt there's much difference in Python, in which case it
makes sense to force PSAPI_VERSION=1 for the build that you distribute. You can
leave it as an option for someone on Windows 7+ building their own copy.
Original comment by eryksun
on 22 Mar 2013 at 10:15
Fine. Can anybody confirm that the patch I attached earlier fixes this problem?
Original comment by g.rodola
on 23 Mar 2013 at 11:22
For Windows 7, WINVER == _WIN32_WINNT == 0x0601, and the test would be WINVER
>= 0x0601.
But why not modify your macro definition in setup.py to ('_WIN32_WINNT',
'0x501'), which targets XP and implicitly sets the psapi, or instead add
('PSAPI_VERSION', 1)?
Windows version macros:
http://msdn.microsoft.com/en-us/library/aa383745
Original comment by eryksun
on 23 Mar 2013 at 4:17
> For Windows 7, WINVER == _WIN32_WINNT == 0x0601, and
> the test would be WINVER >= 0x0601.
Right, thanks. How about now? Can someone try the patch in attachment?
> But why not modify your macro definition in setup.py to
> ('_WIN32_WINNT', '0x501')
Because we're relying on _WIN32_WINNT in different parts of _psutil_mswindows.c.
Original comment by g.rodola
on 26 Mar 2013 at 12:13
Attachments:
What did you need this tested on? XP? I don't have an XP box I can test on at
the moment, just Win 2003 I think.
Original comment by jlo...@gmail.com
on 26 Mar 2013 at 2:02
The original OP's message was talking about Win XP. I have Win XP but I cannot
reproduce the issue though so basically what I need is someone who does.
Original comment by g.rodola
on 26 Mar 2013 at 2:13
Regarding the patch, you call EnumProcesses in process_info.c, so you'd have to
add it there too. Also, you're only defining the _WIN32_WINNT macro in
setup.py, so you need to test _WIN32_WINNT instead. The value of WINVER gets
set to _WIN32_WINNT in the headers included by Windows.h. However, rather than
define this all over the place, you could just do it once in setup.py.
I still don't grok this approach, though. Currently, if someone builds psutil
himself with SDK 7 (Python 3.3 needs this version), he won't see this extension
module import problem. Your setup.py sets _WIN32_WINNT to the build system's
version of NT, which indirectly chooses the correct PSAPI_VERSION. However, if
he builds an installer on NT 6.1+ using SDK 7, the extension module won't work
on NT 5.x/6.0 -- as setup.py currently stands.
It seems the simplest approach is to target the pre-built extension module to
the widest audience possible. It's not as if an XP/Vista consumer of the
pre-built 3.3 extension cares about optimizations for a particular _WIN32_WINNT
version at *build* time. If the build system is NT 6.1+, it's just liable to
break things for them. You can add an option to override the default 0x0501
target for the rare user on Windows that actually builds C extensions from
source.
Original comment by eryksun
on 26 Mar 2013 at 4:22
I'm not sure I'm completely following you here. My knowledge about Windows,
especially when C code is involved is rather limited.
If the problem is clear to you and you can reproduce the issue maybe you can
provide a patch?
The ideal solution would be to fix the problem on all Windows
versions/compilers transparently without involving a cmdline option for
setup.py (if that is what you meant in the first place).
Original comment by g.rodola
on 26 Mar 2013 at 4:29
We were able to fix this for the one user who was seeing it by copying the two
files
_psutil_mswindows.pyc
_psutil_mswindows.pyd
into dist/library/psutil.
See https://groups.google.com/forum/?fromgroups#!topic/psutil/gQa0z872pJI
Original comment by makdaddy98102@gmail.com
on 29 Apr 2013 at 7:05
That's not the best solution though.
I was hoping you could try the patch above, compile psutil, and tell us if that
fixes the issue.
Original comment by g.rodola
on 2 May 2013 at 2:56
Original comment by g.rodola
on 3 May 2013 at 3:20
hi! any news on this one? it's still broken in 1.1.3 on my windows xp box (with
python 3.3). this is a stopper for me. :-(
Original comment by radekpod...@gmail.com
on 18 Nov 2013 at 12:44
I proposed a solution (issue348.patch) asking if somebody could try the patch
and report back but no one did.
I cannot know by myself whether issue348.patch fixes the issue because I cannot
reproduce it.
Original comment by g.rodola
on 18 Nov 2013 at 1:12
i'd be happy to test it but i'm unable to compile it myself... could you
prepare a package so i can just install and test it?
Original comment by radekpod...@gmail.com
on 18 Nov 2013 at 1:25
Ok, I can do that later today when I'll be back home.
What Python version? 32 or 64 bit?
Original comment by g.rodola
on 18 Nov 2013 at 1:31
great! it's python 3.3 (32bit), win xp sp-3 32bit
Original comment by radekpod...@gmail.com
on 18 Nov 2013 at 1:33
I currently cannot compile for Python 3.3.
Here's an installer for Python 2.7 32-bit (please install that one).
Original comment by g.rodola
on 18 Nov 2013 at 6:17
Attachments:
imports fine (and cpu_percent() works) so i'd call it fixed. thanks!
also, if there's nothing else stopping a new release, please do so (our
company's product just migrated to python3 and this turns out to be a
show-stopper). thank you very much.
Original comment by radekpod...@gmail.com
on 19 Nov 2013 at 9:59
I will definitively release a version soon, although I'm not sure when (I hope
someday during this week).
Original comment by g.rodola
on 19 Nov 2013 at 4:12
Fixed in version 1.2.0 which I released a moment ago.
Original comment by g.rodola
on 20 Nov 2013 at 8:33
just installed the 1.2.0 version under python 3.3 and the import fails just as
with the old version. :-( ...so this is unfortunately NOT fixed and seems to be
not only windows xp related but also python 3 related...
Original comment by radekpod...@gmail.com
on 21 Nov 2013 at 12:03
btw, should you need a test-monkey i'd be happy to run and test anything you
give me (compiled). ;-)
Original comment by radekpod...@gmail.com
on 21 Nov 2013 at 12:45
Shit!
What about Python 2.7? Does it fail too?
Original comment by g.rodola
on 21 Nov 2013 at 1:05
no, the 1.2.0 version imports fine under python 2.7.
Original comment by radekpod...@gmail.com
on 21 Nov 2013 at 1:28
That doesn't make any sense to me. They were compiled form the same source code
base.
Original comment by g.rodola
on 21 Nov 2013 at 1:35
Can someone else try 1.2.0 on Windows XP?
Original comment by g.rodola
on 21 Nov 2013 at 1:36
is it compiled using the same compiler (same version)? i thought python3 is
linked to a newer version of msvcr or something (i'm really not familiar with
the details)...
Original comment by radekpod...@gmail.com
on 21 Nov 2013 at 1:46
Refer to comment #13. Your latest build links to kernel32.dll K32EnumProcesses,
instead of psapi.dll EnumProcesses. K32EnumProcesses does not exist prior to
Windows 7.
I don't agree with patching this separately in every compilation unit. Plus,
even if it is done that way, it should be testing the _WIN32_WINNT version that
you define in setup.py. WINVER doesn't get updated to _WIN32_WINNT until after
you include Windows.h.
IMO, just set _WIN32_WINNT to '0x0501' (XP) in setup.py when building for the
distribution that needs to support XP/Vista.
http://code.google.com/p/psutil/source/browse/setup.py?name=release-1.2.0#87
That gives you the old PSAPI without any further mucking around, and it still
runs in all versions of Windows. Or just unconditionally define PSAPI_VERSION
to 1 when building for distribution. Either way, someone can always build a
version targeting a newer Windows version if they so choose.
Original comment by eryksun
on 21 Nov 2013 at 2:25
eryksun: thanks for the help and sorry for not considering your comment #13 but
that's because I don't have a proper understanding of the problem.
Please take a look at file "348.patch" I'm attaching. Is this what you were
suggesting?
radekpodgorny: attached are two compiled versions for Python 2.7 and 3.3 which
were produced after applying the patch in attachment. Could you please try them
and report back?
Original comment by g.rodola
on 21 Nov 2013 at 9:45
Attachments:
sorry to say bad news but it's still the same: works under 2.7 and fails under
3.3.
(yes, i've checked 1.2.1 was actually installed for both pythons in control
panel)
Original comment by radekpod...@gmail.com
on 21 Nov 2013 at 10:40
p.s.: i see you're probably compiling with mingw. don't you have a tutorial on
how to set up the compiling environment you have so can play with it myself?
thank you!
Original comment by radekpod...@gmail.com
on 21 Nov 2013 at 10:43
Take a look at the INSTALL file.
It contains instructions on how to build using mingw32.
Original comment by g.rodola
on 21 Nov 2013 at 10:46
1) installed mingw (actually found some old install on my system)
2) cloned hg version on psutil
3) built it as recommended (-c mingw32) (had to tweak distutils not to pass
-mno-cygwin)
4) installed (setup.py install)
5) succesfully imported in python (3.3)
...so i has to be something related to your build system.
Original comment by radekpod...@gmail.com
on 21 Nov 2013 at 11:26
I use Visual Studio in order to compile for Python 3.3, that's why.
Original comment by g.rodola
on 21 Nov 2013 at 11:41
The extension module in the 1.2.1 build is back to using the kernel32 K32*
functions that aren't available in XP/Vista. In patch 348 if it's not building
on XP (Vista is NT 6.0), _WIN32_WINNT is set to the build system Windows
version returned by get_winver(). But if it's building on XP this isn't even an
issue, and get_winver() would return '0x0501' anyway.
What I proposed was to unconditionally define ('_WIN32_WINNT', '0x0501') or
('PSAPI_VERSION', 1). At least do this for the builds on PyPI.
Using the old PSAPI will work fine on new versions of Windows -- at least for
as long as Microsoft supports psapi.dll. That should be at least until Vista is
no longer supported.
Original comment by eryksun
on 21 Nov 2013 at 11:54
I added ('PSAPI_VERSION', 1) in setup.py.
radekpodgorny here's the new exes.
Original comment by g.rodola
on 22 Nov 2013 at 8:28
Attachments:
works! thank you!
Original comment by radekpod...@gmail.com
on 23 Nov 2013 at 10:45
Committed in revision 195e1eaf4a9c.
Original comment by g.rodola
on 25 Nov 2013 at 6:46
Closing.
Original comment by g.rodola
on 26 Nov 2013 at 8:52
Original comment by g.rodola
on 26 Nov 2013 at 8:52
Original issue reported on code.google.com by
Drydercs...@gmail.com
on 2 Jan 2013 at 1:56