Check for file access

Brian Bull bbull at pathfire.com
Tue Jan 14 18:51:34 CET 2003


Thanks!!! That worked.  Below is my code where self.item is the file I am
waiting on:
----------------------
complete = 0
while(complete != 1):
	command = "/sbin/fuser " + self.item
          status = commands.getoutput(command)
          if(status):
          	self.logMessage("file not complete yet")
                   complete = 0
                   time.sleep(5)
	else:
          	self.logMessage("file complete")
                   complete = 1

----------------------

-----Original Message-----
From: Andrew McGregor [mailto:andrew at indranet.co.nz]
Sent: Tuesday, January 14, 2003 12:42 PM
To: Brian Bull; python-list at python.org
Subject: Re: Check for file access


--On Tuesday, January 14, 2003 06:56:29 -0800 Brian Bull 
<bbull at pathfire.com> wrote:

> I am writing a daemon to monitor file uploads and mirror the files to
> another server once they have been uploaded.  The files will be
> uploaded via Windows filesharing onto my Redhat server that is running
> Samba.  How can I tell when the file is complete and is ready for
> copying?
>
> I am using a kernel module called 'changedfiles' that alerts me when a
> file is changed.  The only problem is this modules alerts me when the
> file operation begins, not when it ends.  The files that will be
> uploaded are CD images so they will be very large, so I have to have
> some sort of way to "wait" until the file is complete.
>
> I have tried opening the file (with read and write permission), but
> that cancels the upload process.  I guess Windows loses the access to
> the file once the server grabs it.
>
> I have also tried checking the size of the file, but that doesn't work
> because the complete size is reported from the first second the file
> is being uploaded.
>
> Any help here would be really appreciated.  If I am not describing
> this well, let me know and I will try to elaborate more.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

Wait until the fuser command (not python function, system command) no 
longer shows any task using that file.  The technique it uses is 
complicated (and brute force), so replicating it in python would be quite a 
bit of work.

Andrew





More information about the Python-list mailing list