En Mon, 18 Jun 2007 16:30:05 -0300, Nick Craig-Wood <[EMAIL PROTECTED]> escribió:
> Tim Williams <[EMAIL PROTECTED]> wrote: >> You can also do this by holding a file open in write mode until the >> script has finished. >> >> try: >> open('lock.txt','w') >> my_script() >> except: >> #print script is already running > > That only works under windows Neither. The same file may be opened many times for writing at the same time, from the same or different processes, even on Windows. So this alone cannot be used as a locking mechanism. > >>> f=open('lock.txt','w') > >>> g=open('lock.txt','w') > >>> f.write('hi') > >>> g.write('ho') > >>> f.close() > >>> g.close() > >>> open('lock.txt').read() > 'ho' The same happens on Windows. A file *can* be opened with exclusive access, but this is not exposed thru the open() function in Python; one should use the CreateFile Win32 API function with adequate flags. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list