Deleting files on a shared server

Steven D'Aprano steve+comp.lang.python at pearwood.info
Thu Oct 6 23:04:57 EDT 2011


Josh English wrote:

> This is a follow-up to some questions I posted a month or two ago. I have
> two programs running on various Windows XP boxes, sharing several resource
> files on a Windows 2003 server. It's a mapped drive on the workstations to
> a shared folder.
> 
> I am using a locking utility that works by creating ".lock" files in the
> shared folder and deleting those files when the program is done with them.
> 
> To delete the files, I am using os.unlink.

How and when? If you are deleting the files using a __del__ handler in an
instance, it is quick possible that it is never being run, or not being run
when you think it is.

For file locking, you should consider using a portable solution like this
one:

http://code.activestate.com/recipes/65203-portalocker-cross-platform-posixnt-api-for-flock-s/

 
> One lock file refuses to disappear, even though I have code at both
> application startup and shutdown (on the OnInit and OnExit methods to the
> wxPython Application object) that hunts down .lock files and deletes them.

Perhaps the file is open and so can't be deleted under Windows. Are you
getting an exception when you try to unlink the file? If so, what does it
say?


> Is there a better command than os.unlink to delete a file on Windows 2003
> server?

No. os.unlink is a wrapper around your system's unlink command -- if it
can't delete the file, you can't delete the file.


-- 
Steven




More information about the Python-list mailing list