Re: Which version of MSVC?90.DLL's to distribute with Python 2.6 based Py2exe executables?
I tried on a fresh XP on VM. I moved all dlls in C:\WINDOWS\WinSxS which are in the file handles shown by Process Explorer including the 3 CRT dlls to the my dist folder and the two subfolders suggested by http://wiki.wxpython.org/py2exe. It didn't work out. My app couldn't start. Windows XP gave a cryptic error asking me to reinstall the app. After installing vcredist_x86.exe, my app starts fine. There isn't a choice here. You HAVE TO bundle vcredist_x86.exe with your installer and convince your customers that it is necessary to increase the file size by 2MB. If anyone figure out how to do as http://wiki.wxpython.org/py2exe, or on a Python compiled with a free GNU compiler, avoiding all these BS. I will pay him/her $10. -- http://mail.python.org/mailman/listinfo/python-list
save windows clipboard content temporarily and restore later
Is there a way to: 1. save windows clipboard content temporarily in a variable 2. (the clipboard content is then overwritten by some other applications) 3. restore the saved data back into the clipboard. ? I've tried win32clipboard's GetClipboardData, SetClipboardData. The GetClipboardData method is able to retrieve clipboard content only after a format is specified. Restoring the data with that format could result in information loss, for example when HTML text is saved in ordinary text format. There is no format that could preserve 100% of any kind of clipboard content. Does anyone has a brilliant solution? -- http://mail.python.org/mailman/listinfo/python-list
Re: save windows clipboard content temporarily and restore later
On Oct 9, 11:30 am, Neil Hodgson wrote: > kakarukeys: > > > Restoring the data with that format could result in information loss, > > for example when HTML text is saved in ordinary text format. There is > > no format that could preserve 100% of any kind of clipboard content. > > > Does anyone has a brilliant solution? > > Enumerate all the clipboard formats with EnumClipboardFormats and > grab the contents in each format then put them all back when finished. > > Neil Hi Neil, I followed your hints, and wrote the following code. It works for most clipboard formats except files. Selecting and copying a file, followed by backup() and restore() throw an exception: Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from test12 import * >>> backup() >>> restore() Traceback (most recent call last): File "", line 1, in File "test12.py", line 40, in restore win32clipboard.SetClipboardData(format, cb[format]) TypeError: expected a readable buffer object >>> If I try to skip the error, pasting into a folder creates a file named 'scrap' with more or less the same content as the copied file. Is there any solution? import win32clipboard storage = [] def backup(): cb = {} win32clipboard.OpenClipboard() format = 0 try: while True: format = win32clipboard.EnumClipboardFormats(format) if format == 0: break else: try: RawData = win32clipboard.GetClipboardData(format) except: continue else: cb[format] = RawData finally: win32clipboard.CloseClipboard() storage.append(cb) def restore(): if storage != []: win32clipboard.OpenClipboard() try: win32clipboard.EmptyClipboard() cb = storage.pop() for format in cb: win32clipboard.SetClipboardData(format, cb[format]) finally: win32clipboard.CloseClipboard() -- http://mail.python.org/mailman/listinfo/python-list
Re: save windows clipboard content temporarily and restore later
On Oct 10, 6:00 am, Neil Hodgson wrote: > kakarukeys: > > > I followed your hints, and wrote the following code. It works for most > > clipboard formats except files. Selecting and copying a file, followed > > by backup() and restore() throw an exception: > > For some formats the handle stored on the clipboard may not be a > memory handle so may not be retrieved as memory. You could try using a > list of formats to include or exclude or just pass over the exception. > > Neil The exception occurred not when the program was trying to retrieve the clipboard data, but when calling SetClipboardData to write to clipboard. So I don't think what you said is the cause of the problem. -- http://mail.python.org/mailman/listinfo/python-list
control CPU usage
Hi, When I am running a loop for a long time, calculating heavily, the CPU usage is at 100%, making the comp not so responsive. Is there a way to control the CPU usage at say 80%? putting a time.sleep(0.x) doesn't seem to help although CPU usage level is reduced, but it's unstable. Regards, W.J.F. -- http://mail.python.org/mailman/listinfo/python-list
Re: control CPU usage
On Sep 20, 6:24 pm, Dave Angel wrote: > Jiang Fung Wong wrote: > > Dear All, > > > Thank you for the information. I think I've some idea what the problem is > > about after seeing the replies. > > > More information about my system and my script > > > PIII 1Ghz, 512MB RAM, Windows XP SP3 > > > The script monitors global input using PyHook, > > and calculates on the information collected from the events to output some > > numbers. Based on the numbers, the script then performs some automation > > using SendKeys module. > > > here is the memory usage: > > firefox.exe, 69MB, 109MB > > svchost.exe, 26MB, 17MB > > pythonw.exe, 22MB, 17MB > > searchindexer.exe, 16MB, 19MB > > > My first guess is that the script calculated for too long time after > > receiving an event before propagating it to the default handler, resulting > > the system to be non-responsive. I will try to implement the calculation > > part in another thread. > > Then the separate will have 100% CPU usage, hope the task scheduling of > > Windows works in my favour. > > (You top-posted this message, putting the whole stream out of order. So > I deleted the history.) > > All my assumptions about your environment are now invalid. You don't > have a CPU-bound application, you have a Windows application with event > loop. Further, you're using SendKeys to generate a keystroke to the > other process. So there are many things that could be affecting your > latency, and all my previous guesses are useless. > > Adding threads to your application will probably slow the system down > much more. You need to find out what your present problem is before > complicating it. > > You haven't really described the problem. You say the system is > unresponsive, but you made it that way by creating a global hook; a > notoriously inefficient mechanism. That global hook inserts code into > every process in the system, and you've got a pretty low-end environment > to begin with. So what's the real problem, and how severe is it? And > how will you measure improvement? The Task manager numbers are probably > irrelevant. > > My first question is whether the pyHook event is calling the SendKeys > function directly (after your "lengthy" calculation) or whether there > are other events firing off in between. If it's all being done in the > one event, then measure its time, and gather some statistics (min time, > max time, average...). The task manager has far too simplistic > visibility to be useful for this purpose. > > What else is this application doing when it's waiting for a pyHook > call? Whose event loop implementation are you using? And the program > you're trying to control -- is there perhaps another way in? > > DaveA Hi, Sorry I wasn't sure how to use Google groups to post a msg to the newsgroup, I used Gmail to write my previous reply. What you and the other guy have provided me isn't useless. Now I understand the non- responsiveness may not be caused by high CPU usage, as the OS, be it Windows or Linux, has a way to prioritize the tasks. This is a vital clue to me. By "not responsive", I mean, for some time, the mouse pointer is not moving smoothly, to such extent that I can't do anything with the mouse. It's like playing a multi-player game on a connection with a lot of lag. It's not caused by global hook, because it happens under certain condition, i.e. when fpa.ProcessEvent(word) is computing. I included my main script for your reference. Comments: (1) The automation method tc.Auto() is slow, but it doesn't cause any problem, because the user would wait for the automation to finish, before he continues to do something. (2) all other methods invoked are fast, except fpa.ProcessEvent(word) (this information is obtained from profiling). It is this method that causes 100% CPU usage. I'm planning to move this method to a separate thread, so that OnEvent(event) can finish executing, while the separate thread goes on to finish its calculation. Is this a good idea? import pyHook import TypingAnalyzer import GUI def OnEvent(event): if hasattr(event, "Key") and event.Ascii == 9 and event.Key == "Tab" and event.Injected == 0 and event.Alt == 0: tc.Auto() return False else: recognized = rk.ProcessEvent(event) if recognized: tc.MatchChar(recognized) paragraph = rc.ProcessEvent(recognized) if paragraph: for word in paragraph: fpa.ProcessEvent(word) return True hm = pyHook.HookManager() hm.MouseAllButtonsDown = OnEvent hm.KeyDown = OnEvent hm.HookMouse() hm.HookKeyboard() rk = TypingAnalyzer.ReadKey() rc = TypingAnalyzer.ReadChar() fpa = TypingAnalyzer.Analysis() tc = TypingAnalyzer.Automation(fpa) if __name__ == '__main__': app = GUI.AWAApp() app.MainLoop() Thank you for your attention. -- ht
Re: control CPU usage
On Sep 20, 10:57 pm, Dave Angel wrote: > kakarukeys wrote: > > On Sep 20, 6:24 pm, Dave Angel wrote: > > >> Jiang Fung Wong wrote: > > >>> Dear All, > > >>> Thank you for the information. I think I've some idea what the problem is > >>> about after seeing the replies. > > >>> More information about my system and my script > > >>> PIII 1Ghz, 512MB RAM, Windows XP SP3 > > >>> The script monitors global input using PyHook, > >>> and calculates on the information collected from the events to output some > >>> numbers. Based on the numbers, the script then performs some automation > >>> using SendKeys module. > > >>> here is the memory usage: > >>> firefox.exe, 69MB, 109MB > >>> svchost.exe, 26MB, 17MB > >>> pythonw.exe, 22MB, 17MB > >>> searchindexer.exe, 16MB, 19MB > > >>> My first guess is that the script calculated for too long time after > >>> receiving an event before propagating it to the default handler, resulting > >>> the system to be non-responsive. I will try to implement the calculation > >>> part in another thread. > >>> Then the separate will have 100% CPU usage, hope the task scheduling of > >>> Windows works in my favour. > > >> (You top-posted this message, putting the whole stream out of order. So > >> I deleted the history.) > > >> All my assumptions about your environment are now invalid. You don't > >> have a CPU-bound application, you have a Windows application with event > >> loop. Further, you're using SendKeys to generate a keystroke to the > >> other process. So there are many things that could be affecting your > >> latency, and all my previous guesses are useless. > > >> Adding threads to your application will probably slow the system down > >> much more. You need to find out what your present problem is before > >> complicating it. > > >> You haven't really described the problem. You say the system is > >> unresponsive, but you made it that way by creating a global hook; a > >> notoriously inefficient mechanism. That global hook inserts code into > >> every process in the system, and you've got a pretty low-end environment > >> to begin with. So what's the real problem, and how severe is it? And > >> how will you measure improvement? The Task manager numbers are probably > >> irrelevant. > > >> My first question is whether the pyHook event is calling the SendKeys > >> function directly (after your "lengthy" calculation) or whether there > >> are other events firing off in between. If it's all being done in the > >> one event, then measure its time, and gather some statistics (min time, > >> max time, average...). The task manager has far too simplistic > >> visibility to be useful for this purpose. > > >> What else is this application doing when it's waiting for a pyHook > >> call? Whose event loop implementation are you using? And the program > >> you're trying to control -- is there perhaps another way in? > > >> DaveA > > > Hi, > > > Sorry I wasn't sure how to use Google groups to post a msg to the > > newsgroup, I used Gmail to write my previous reply. What you and the > > other guy have provided me isn't useless. Now I understand the non- > > responsiveness may not be caused by high CPU usage, as the OS, be it > > Windows or Linux, has a way to prioritize the tasks. This is a vital > > clue to me. > > > By "not responsive", I mean, for some time, the mouse pointer is not > > moving smoothly, to such extent that I can't do anything with the > > mouse. It's like playing a multi-player game on a connection with a > > lot of lag. It's not caused by global hook, because it happens under > > certain condition, i.e. when fpa.ProcessEvent(word) is computing. > > > I included my main script for your reference. Comments: > > (1) The automation method tc.Auto() is slow, but it doesn't cause any > > problem, because the user would wait for the automation to finish, > > before he continues to do something. > > > (2) all other methods invoked are fast, except fpa.ProcessEvent(word) > > (this information is obtained from profiling). It is this method that > > causes 100% CPU usage. I'm planning to move this method to a separate > > thread, so that OnEvent(event) can finish executing, while the > >