Re: monitoring the filesystem for changes
> i have designed a desktop search utility in python and a file system > monitoring using readdirectorychangesw from win32api but for eg. it > has a high cpu utilization (using a 2GHz processor). I don't think so. I just build a service to monitor a directory changes using readdirectorychangesw, the cpu usage is not above 1.9% for this service(my computer's cpu is 1.7GHz). if you still think 1.9% is high cpu utilization, I think you can use the c to implements this function, the cpu usage seems none for this application(I tried c dll solution first). Wish this help to you. Wang Wei -- http://mail.python.org/mailman/listinfo/python-list
Re: monitoring the filesystem for changes
> You could use the ReadDirectoryChangesW in overlapped > mode. I've never tried it, so I don't know how > robust it would be. Why is it a problem to have > "multiple programs" running? And is that simply > multiple threads, or multiple processes? I used overlapped in my program, it runs about 1 week, seems no problems now. FILE_LIST_DIRECTORY = 0x0001 hDir = None def __init__(self, directory): self.hDir = win32file.CreateFile ( directory, self.FILE_LIST_DIRECTORY, win32con.FILE_SHARE_READ | win32con.FILE_SHARE_WRITE, None, win32con.OPEN_EXISTING, win32con.FILE_FLAG_BACKUP_SEMANTICS| win32con.FILE_FLAG_OVERLAPPED, None ) but I didn't try use multiple program do the same action. I think only one thread to do directory monitor is enough. other thread and process can communicate with it use thread or process communication. Wang Wei -- http://mail.python.org/mailman/listinfo/python-list
a bug in python windows service?
I feel really puzzled about fellowing code, please help me finger out what problem here. import threading class workingthread(threading.Thread): def __init__(self): self.quitEvent = threading.Event() self.waitTime = 10 threading.Thread.__init__(self) def run(self): while not self.quitEvent.isSet(): self.quitEvent.wait(self.waitTime) def join(self, timeout = None): self.quitEvent.set() threading.Thread.join(self, timeout) import win32serviceutil import win32event class testTime(win32serviceutil.ServiceFramework): _svc_name_ = "testTime" _svc_display_name_ = "testTime" _svc_deps_ = ["EventLog"] def __init__(self, args): win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.thread = workingthread() def SvcStop(self): win32event.SetEvent(self.hWaitStop) def SvcDoRun(self): self.thread.run() win32event.WaitForSingleObject(self.hWaitStop, win32event.INFINITE) self.thread.join() if __name__ == '__main__': win32serviceutil.HandleCommandLine(testTime) each time I got the fellowing result, anyone can point out what's wrong in it? E:\code\monitor2>testTime.py debug Debugging service testTime- press Ctrl+C to stop. Stopping debug service. Error 0xC003 - The instance's SvcRun() method failed File "C:\Python24\Lib\site-packages\win32\lib\win32serviceutil.py", line 785, in SvcRun self.SvcDoRun() File "E:\code\monitor2\testTime.py", line 35, in SvcDoRun self.thread.run() File "E:\code\monitor2\testTime.py", line 12, in run self.quitEvent.wait(self.waitTime) File "C:\Python24\lib\threading.py", line 348, in wait self.__cond.wait(timeout) File "C:\Python24\lib\threading.py", line 222, in wait _sleep(delay) exceptions.IOError: (4, 'Interrupted function call') -- http://mail.python.org/mailman/listinfo/python-list
Re: a bug in python windows service?
> No, this is not a bug. You must not call Thread.run(), use Thread.start() > instead - else your code won't run in a different thread of execution. See > http://docs.python.org/lib/thread-objects.htmlon how to use Thread > objects - and note that you should *only* override __init__ and run, if > any. > Instead of extending join(), write a specific method to signal the > quitEvent or just let the caller signal it. And I don't see in this > example why do you need two different events (one on the thread, another > on the service controller), a single event would suffice. > > -- > Gabriel Genellina Thanks for help, It works now:D -- http://mail.python.org/mailman/listinfo/python-list
Re: a bug in python windows service?
> Instead of extending join(), write a specific method to signal the > quitEvent or just let the caller signal it. And I don't see in this > example why do you need two different events (one on the thread, another > on the service controller), a single event would suffice. I don't think a single event is enought, since I think the event python created and windows event are not same kind of event. -- http://mail.python.org/mailman/listinfo/python-list
Re: a bug in python windows service?
On May 27, 11:25 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Sun, 27 May 2007 09:07:36 -0300, momobear <[EMAIL PROTECTED]> escribió: > > >> Instead of extending join(), write a specific method to signal the > >> quitEvent or just let the caller signal it. And I don't see in this > >> example why do you need two different events (one on the thread, another > >> on the service controller), a single event would suffice. > > > I don't think a single event is enought, since I think the event > > python created and windows event are not same kind of event. > > They are not the same object, of course (altough the threading.Event > object relies eventually on a mutex implemented using CreateEvent). But in > this case both can be successfully used; of course, having the Python > object a more "pythonic" interfase (not a surprise!), it's easier to use. > The same example modified using only a threading.Event object (and a few > messages to verify how it runs): > > import threading > from win32api import OutputDebugString as ODS > > class workingthread(threading.Thread): > def __init__(self, quitEvent): > self.quitEvent = quitEvent > self.waitTime = 1 > threading.Thread.__init__(self) > > def run(self): > while not self.quitEvent.isSet(): > ODS("Running...\n") > self.quitEvent.wait(self.waitTime) > ODS("Exit run.\n") > > import win32serviceutil > import win32event > > class testTime(win32serviceutil.ServiceFramework): > _svc_name_ = "testTime" > _svc_display_name_ = "testTime" > _svc_deps_ = ["EventLog"] > > def __init__(self, args): > win32serviceutil.ServiceFramework.__init__(self, args) > self.hWaitStop = threading.Event() > self.thread = workingthread(self.hWaitStop) > > def SvcStop(self): > self.hWaitStop.set() > > def SvcDoRun(self): > self.thread.start() > self.hWaitStop.wait() > self.thread.join() > > if __name__ == '__main__': > win32serviceutil.HandleCommandLine(testTime) > > -- > Gabriel Genellina Great! thanks, now I understand the real work of the python windows service. -- http://mail.python.org/mailman/listinfo/python-list
Re: Speex bindings for python 2.5
> I forgot to give the url :http://www.freenet.org.nz/python/pySpeex/ I Couldn't Open the website. -- http://mail.python.org/mailman/listinfo/python-list
Re: Key Listeners
On May 30, 10:14 am, Mike <[EMAIL PROTECTED]> wrote: > Are there key listeners for Python? Either built in or third party? try "pykeylogger", that's maybe u want. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print this character u'\u20ac' to DOS terminal
On May 30, 3:05 pm, 人言落日是天涯,望极天涯不见家 <[EMAIL PROTECTED]> wrote: > On 5月30日, 下午1时23分, "Martin v. Lo"wis" <[EMAIL PROTECTED]> wrote: > > > > > 人言落日是天涯,望极天涯不见家 schrieb: > > > > Who could explain the follow issue ? > > print u'\u0394' > > > Δ > > print u'\u20ac' > > > Traceback (most recent call last): > > > File "", line 1, in > > > UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in > > > position 0: > > > illegal multibyte sequence > > > > My terminal is cmd.exe under windows XP. > > > what's the different between the two character ? what can I do if I > > > want to print the u'\u20ac'? > > > The problem is that your terminal uses (some form of) the GBK encoding; > > seehttp://zh.wikipedia.org/wiki/GBKfordetails on GBK. > > > It seems that GBK (or, rather, code page 936) supports the delta > > character, but not the euro sign. > > > To change that, you can use "chcp" in your terminal window. > > For example, if you do "chcp 850", you should be able to > > display the euro sign (but will simultaneously use the ability > > to display the letter delta, and the chinese letters). > > > I don't know whether the terminal supports an UTF-8 code > > page; you can try setting the terminal's code page to > > 65001 (which should be UTF-8). > > > Regards, > > Martin > > Thanks, but it seems not work yet. > > > C:\WINDOWS>chcp 850 > Active code page: 850 > > C:\WINDOWS>python > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information.>>> > print u'\u20ac' > > Traceback (most recent call last): > File "", line 1, in > File "C:\Python25\lib\encodings\cp850.py", line 12, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac' > in position > 0: character maps to > > C:\WINDOWS>chcp 65001 > Active code page: 65001 > > C:\WINDOWS>python > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information.>>> > print u'\u20ac' > > Traceback (most recent call last): > File "", line 1, in > LookupError: unknown encoding: cp65001 > --- > I find that the u'\u20ac' related 'mbcs' encode is 0x80, I could print > it directly > > >>> print '\x80' > � > > But the string contained the u'\u20ac' is get from remote host. Is > there any method to decode it to the local 'mbcs'? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to print this character u'\u20ac' to DOS terminal
On May 30, 3:05 pm, 人言落日是天涯,望极天涯不见家 <[EMAIL PROTECTED]> wrote: > On 5月30日, 下午1时23分, "Martin v. Lo"wis" <[EMAIL PROTECTED]> wrote: > > > > > 人言落日是天涯,望极天涯不见家 schrieb: > > > > Who could explain the follow issue ? > > print u'\u0394' > > > Δ > > print u'\u20ac' > > > Traceback (most recent call last): > > > File "", line 1, in > > > UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in > > > position 0: > > > illegal multibyte sequence > > > > My terminal is cmd.exe under windows XP. > > > what's the different between the two character ? what can I do if I > > > want to print the u'\u20ac'? > > > The problem is that your terminal uses (some form of) the GBK encoding; > > seehttp://zh.wikipedia.org/wiki/GBKfordetails on GBK. > > > It seems that GBK (or, rather, code page 936) supports the delta > > character, but not the euro sign. > > > To change that, you can use "chcp" in your terminal window. > > For example, if you do "chcp 850", you should be able to > > display the euro sign (but will simultaneously use the ability > > to display the letter delta, and the chinese letters). > > > I don't know whether the terminal supports an UTF-8 code > > page; you can try setting the terminal's code page to > > 65001 (which should be UTF-8). > > > Regards, > > Martin > > Thanks, but it seems not work yet. > > > C:\WINDOWS>chcp 850 > Active code page: 850 > > C:\WINDOWS>python > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information.>>> > print u'\u20ac' > > Traceback (most recent call last): > File "", line 1, in > File "C:\Python25\lib\encodings\cp850.py", line 12, in encode > return codecs.charmap_encode(input,errors,encoding_map) > UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac' > in position > 0: character maps to > > C:\WINDOWS>chcp 65001 > Active code page: 65001 > > C:\WINDOWS>python > Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit > (Intel)] on > win32 > Type "help", "copyright", "credits" or "license" for more information.>>> > print u'\u20ac' > > Traceback (most recent call last): > File "", line 1, in > LookupError: unknown encoding: cp65001 > --- > I find that the u'\u20ac' related 'mbcs' encode is 0x80, I could print > it directly > > >>> print '\x80' > � > > But the string contained the u'\u20ac' is get from remote host. Is > there any method to decode it to the local 'mbcs'? forgot to unicode(string) before send it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Periodic tasks.
On May 29, 2:33 pm, Ramashish Baranwal <[EMAIL PROTECTED]> wrote: > Hi, > > I am trying to execute some tasks periodically, those familiar with > unix can think of it as equivalent to cron jobs. I have tried looking > around, but couldn't find a way. Would appreciate any pointers or > clues.. > > Thanks, > -Ram I googled "twisted cron", if u use twisted, that's maybe help u: http://svn.zope.org/Zope3/trunk/src/scheduler/cron.py?rev=38967&view=auto http://twistedmatrix.com/pipermail/twisted-python/2006-June/013525.html -- http://mail.python.org/mailman/listinfo/python-list
Any way to monitor windows network connection?
hi, Is there any way to show me detailed listings of all TCP and UDP endpoints in my microsoft windows XP in python way? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any way to monitor windows network connection?
On Aug 1, 1:47 pm, Gordon Airporte <[EMAIL PROTECTED]> wrote: > momobear wrote: > > hi, Is there any way to show me detailed listings of all TCP and UDP > > endpoints in my microsoft windows XP in python way? > > thanks. > > Unless you're looking for a programming > exercise:http://www.microsoft.com/technet/sysinternals/Utilities/TcpView.mspx Ok, It works, but there're no source code of it. I wish to build a tools to show all the network endpoints, cpu usage and top ten processes in a dockapp like application. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any way to monitor windows network connection?
On Aug 1, 12:22 pm, Jay Loden <[EMAIL PROTECTED]> wrote: > momobear wrote: > > hi, Is there any way to show me detailed listings of all TCP and UDP > > endpoints in my microsoft windows XP in python way? > > thanks. > > Not sure if it's exactly what you're looking for, but this might be of use as > a starting point at > least:http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/392572 yes, I get it, iphelp api could do that for me. thanks for help. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help: GIS
On Aug 3, 11:46 am, zxo102 <[EMAIL PROTECTED]> wrote: > Hi, > I am new in GIS area and need your suggestions for where I can > start from. I have a python based web application with a database. > Now I would like to add a GIS map into my application. When a user > clicks a certain area in the GIS map, it can grab the data from the > database via my python based application. Do I have to use MapServer > or Grass or some other backends for this purpose? >Thanks a lot. > > Ouyang another link, http://code.djangoproject.com/wiki/GeoDjango, talk about many python tools about GIS, hope help to u. -- http://mail.python.org/mailman/listinfo/python-list
any ways to judge whether an object is initilized or not in a class
hi, I am puzzled about how to determine whether an object is initilized in one class, anyone could give me any instructions? here is an example code: class coffee: def boil(self): self.temp = 80 a = coffer() if a.temp > 60: print "it's boiled" in C++ language we must initilized a variable first, so there is no such problem, but in python if we don't invoke a.boil(), we will not get self.temp to be initilized, any way to determine if it's initilzed before self.temp be used. -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
On Mar 19, 4:19 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > momobear schrieb: > > > > > hi, I am puzzled about how to determine whether an object is > > initilized in one class, anyone could give me any instructions? > > here is an example code: > > > class coffee: > > def boil(self): > >self.temp = 80 > > > a = coffer() > > if a.temp > 60: > > print "it's boiled" > > > in C++ language we must initilized a variable first, so there is no > > such problem, but in python if we don't invoke a.boil(), we will not > > get self.temp to be initilized, any way to determine if it's initilzed > > before self.temp be used. > > You want boil to be called __init__, which is python's constructor name. > Then it will be called in a statement like > > a = coffee() > > automatically. > > Diez sorry, I should add more code to implement my ideas. class coffee: def __init__(self): ''' do something here ''' def boil(self): self.temp = 80 a = coffer() if a.temp > 60: print "it's boiled" -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
On Mar 19, 4:50 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > "momobear" <[EMAIL PROTECTED]> wrote: > > in C++ language we must initilized a variable first, so there is no > > such problem, but in python if we don't invoke a.boil(), we will not > > get self.temp to be initilized, any way to determine if it's initilzed > > before self.temp be used. > > The simplest thing is simply never to attempt to use a variable or an > attribute until you know that is has been initialized, so initialize all > variables before using them, and initialize all attributes in the class's > __init__ method. > > If you don't have a suitable value for the attribute until later then just > start off with None and then you can check for 'a.boil is not None': if you > forget to check then Python's strong type checking will stop you from using > the None value in an expression expecting a number (or a string). > > For cases where you aren't sure whether an object has a specific attribute > you can use getattr with 3 arguments: > >if getattr(a, 'boil', 80): >... > > If that isn't convenient (or it's a variable rather than an attribute) you > should fall back on the principle that 'is it better to ask forgiveness > than permission': i.e. just try to use the value and handle the exception > which is thrown if it doesn't exist. (If the fallback is to substitute a > simple value use getattr, if the fallback is complicated or takes a long > time to calculate use exception handling). > > There is also a function 'hasattr' which will tell you whether or not the > object has the specified attribute, but internally it just calls 'getattr' > and handles the exception so (IMHO) it is generally best just not to bother > with 'hasattr'. thanks for help:), I am puzzled about if I have to use try and except to determine it. finnal code should like this? class coffee: def __init__(self): ''' do something here ''' def boil(self): self.temp = 80 a = coffer() try: if a.temp > 60: print "it's boiled" except AttributeError: print "it's not boiled" -- http://mail.python.org/mailman/listinfo/python-list
how can I invoke a Java code?
A friend of my write a Java program, and I want use it in my python program as a module. I searched the topic in Google and find maybe the better way is use GCJ to compile it. Is there any other way for me? the simple and speediness choice the better. thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: how can I invoke a Java code?
> If you're wanting to interact with the code, your best option may be > Jython, an implementation of Python in Java. I do have to interact with Java module, and when talk about Jython, since I use third parts of python modules I am puzzled about it. -- http://mail.python.org/mailman/listinfo/python-list
draw like windows performance Graph
Type the "taskmgr", Windows performance Graph give a really nice dynamic history curve, It will be wonderful If I could use the same kind of graph to represent the network flow in my python program. Is there a windows api for this graph drawing? -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I find out the size of a file
On Mar 29, 6:09 am, [EMAIL PROTECTED] wrote: > Hi, > > How can I find out the size of a file in a disk in python? > > i try this, but it does not work: > size = open(inputFileNameDir + "/" + file, 'r').size() > > Thank for any help. os.stat(filename), see stat manual for detail.(st_size ) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to tell when a file is opened
> Will look into NTFS change journals when I get some spare time. How can we get NTFS change journals? Is there any API for this purpose or we could implement our own? there're an api in windows help us montior file changes. win32file.ReadDirectoryChangesW -- http://mail.python.org/mailman/listinfo/python-list
Re: Balloon Taskbar Popup for Windows XP
On Sep 29, 6:40 pm, makko <[EMAIL PROTECTED]> wrote: > Greetings, > I need to create a function that will produce a balloon popup in the > taskbar when called. Whats the shortest and easiest way to do this? > Thanks. > > regards, > Makko look at the website, maybe helpful to you. http://xoomer.alice.it/infinity77/main/freeware.html -- http://mail.python.org/mailman/listinfo/python-list
what's wrong with www.planetpython.org?
hi, Does anyone know why the www.planetpython.org could not be connected recently? thanks. -- http://mail.python.org/mailman/listinfo/python-list
what's difference usage?
while as I try to wrap a function using boost-python, I find a strange situation. #include #include #include #include #include using namespace boost::python; int printlist(list &l){ std::vector a; a.push_back("c++"); a.push_back("javascript"); for (std::vector::iterator p = a.begin(); p != a.end(); + +p) l.append(*p); return 0; } BOOST_PYTHON_MODULE(wlist){ def("printlist", printlist); } in the up code,"int printlist(list &l)" at first time I missed add & left of l. but when I run the following python code, #!/usr/local/bin/python a = list() a.append('linux') import wlist wlist.printlist(a) print a they get the same result. linux c++ javascript anyone help me figure out what's wrong here. thanks. -- http://mail.python.org/mailman/listinfo/python-list
does python could support sequence of short or int?
hi, is there a way to let python operate on sequence of int or short? In C, we just need declare a point, then I could get the point value, just like: short* k = buffer, //k is a point to a sequence point of short. short i = *k++, but python is a dynamic language, a = buffer i = ? I don't know how to continue, what's a? a seems to be a str? -- http://mail.python.org/mailman/listinfo/python-list
Re: does python could support sequence of short or int?
but what about buffer is not be declared in python program, it comes from a C function. and what about I want to treat a string as a short list? buffer = foobur() // a invoke from C function, it is encapsulated as a string but I want to treat it as a short list. how can I? -- http://mail.python.org/mailman/listinfo/python-list
Re: does python could support sequence of short or int?
then how can I convert it to a int list? I read about struct and array, I think they are not suitable, since I don't know how long will the buffer is. I know if I write a plugins modules in C should works, but that's really upset to tell to myself there is no way in Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: does python could support sequence of short or int?
thanks for help. formerly I only know to use the struct like bellow: >>> unpack('hhl', '\x00\x01\x00\x02\x00\x00\x00\x03') Great, python can work like this: >>> l = list(struct.unpack('h'*(len(s)/2), s)) I will try to use the numarray also >>>there are some good exensions for Python, >>>numarray and numpy and so on ... >>>(http://numeric.scipy.org/) -- http://mail.python.org/mailman/listinfo/python-list
Re: wxpython in action book
Butternut squash wrote: > any recommendations? any opinions? > > I want to learn to program in python and need a gui reference. I'll be > updating various mysql tables. I have most of the code ready to roll by > using a command line. I need put some lipstick on my project. > > pyQT seems viable but there is not really a good reference and tutorial > > so now I'm considering wxPython and saw this book and I'm wanting to know if > if's even worth spending my $40 on. > > Thanks. what about pygtk, do u have any idea ab it? -- http://mail.python.org/mailman/listinfo/python-list