Regarding question 2, about only receiving one number for two cores, I have a counter in the loop which gets incremented each time the loop runs. This counter always ends up at 1, not 2, so it is only incremented once. When I first started this last week I did put any returns into a list, but the list was always just one element long. This seems to tell me that I am only getting one number, but I should be getting two. Is there a syntax thing that I am missing or confused about, or is wmi refusing me the information about my other core? Is there a different class I should be using to get the load per core?

As far as pyHook, it sounds like it is not going to work too well. Are you saying it could be the cause of the wmi troubles? If so, is there another library I should use instead? I want this to be a global thing, so no matter where in Windows you are, you need only press a hotkey to hear the status of your hardware, like a sighted person need only glance at their resource monitor gadget/sidebar app. For that reason I avoided pyGame and wx since, as I understand it, they only monitor keypresses in their windows, not through the entire system.

Finally, when you say "calling pythoncom.CoInitialize() in every callback", what do you mean by 'callback'?


Have a great day,
Alex
Email: mehg...@gmail.com
----- Original Message ----- From: "Tim Roberts" <t...@probo.com>
To: "Python-Win32 List" <python-win32@python.org>
Sent: Friday, January 15, 2010 13:33
Subject: Re: [python-win32] WMI troubles!


Alex Hall wrote:

Anyway, onto the problem. I am working on a simple resource monitor (I
have never found one that works well with screen readers, so I am
writing one). I am using python2.6 with all the win32 libs installed.
My monitor will use wmi to get all of its information, and it was
going pretty well until a few hours ago, when I started receiving
seemingly random errors. I can call my functions, such as getFreeRam
or getLoad, with no problem as long as the call is hard-coded into the
script. However, when I try to call said functions from a function
monitoring keyboard input (using pyHooks), I get an error and the
program crashes (at least it did until I put a try/except in there,
but hitting the hotkey over and over always gives me an error).

Windows hooks run in a unique environment.  When you install a Windows
hook, you are actually injecting a DLL into every process in the
system.  (It's not a low overhead operation!)  The code in the keyboard
hook runs as part of another processs.

Now, I have not looked into the pyHooks code to see if they are managing
that, by using some kind of inter-process communication.  If they are
not, then you are very limited in what you can do in your callback.
"print" wouldn't work, because that process has a different standard
output.  You would need to send a signal back to your own process.
Further, COM will not have been initialized in that other thread, so you
wouldn't be able to use a COM object, like "Say.Tools".  You can try
calling pythoncom.CoInitialize() in every callback, I suppose.


I will paste the entire file below. It is not very commented yet, so
if something does not make sense, please let me know. My questions are:

1. Why am I getting these errors?

What errors do you get?  I don't think you told us that.


2. The getLoad function only returns one number (the counter is there
to double check that the loop really only runs once). I have a dual
core AMD, so I expected two numbers, a LoadPercentage for each core,
not just one number. How do I get the load per core, not per physical
processor?

Well, it only returns one value because you overwrite the value of
"load" every time through the loop.  If you want to return multiple
values, you should add each new value to a list, and return the list.


3. Regarding pyHook: I press my win-` hotkey on the desktop and get
something to happen in my script, which is good. However, I also get a
Windows error sound. Is there a way to grab that keystroke before
Windows can get it to avoid what seems to be passing the keystroke to
the active app before my script can get it? I tried returning False in
my keyUp function but that made no difference.

This shouldn't be an issue.  The hotkeys are handled by Explorer, which
sucks up the key after it launches your program.  I don't understand who
would trigger the sound.

--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to