is file open in system ? - other than lsof

Brian breily at gmail.com
Wed Apr 16 10:11:09 EDT 2008


On Wed, Apr 16, 2008 at 10:00 AM, Chris McAloney <mcaloney at gmail.com> wrote:

> On 16-Apr-08, at 9:20 AM, A.T.Hofkamp wrote:
> > On 2008-04-16, bvidinli <bvidinli at gmail.com> wrote:
> >> is there a way to find out if file open in system ? -
> >> please write if you know a way  other than lsof. because lsof if
> >> slow for me.
> >> i need a faster way.
> >> i deal with thousands of files... so, i need a faster / python way
> >> for this.
> >> thanks.
> >
> > This is not a Python question but an OS question.
> > (Python is not going to deliver what the OS doesn't provide).
> >
> > Please first find an alternative way at OS level (ie ask this
> > question at an
> > appropiate OS news group). Once you have found that, you can think
> > about Python
> > support for that alternative.
>
> I agree with Albert that this is very operating-system specific.
> Since you mentioned 'lsof', I'll assume that you are at least using a
> Unix variant, meaning that the fcntl module will be available to you,
> so you can check if the file is already locked.
>
> Beyond that, I think more information on your application would be
> necessary before we could give you a solid answer.  Do you only need
> to know if the file is open, or do you want only the files that are
> open for writing?  If you only care about the files that are open for
> writing, then checking for a write-lock with fcntl will probably do
> the trick. Are you planning to check all of the "thousands of files"
> individually to determine if they're open?  If so, I think it's
> unlikely that doing this from Python will actually be faster than a
> single 'lsof' call.
>
> If you're on Linux, you might also want to have a look at the /proc
> directory tree ("man proc"), as this is where lsof gets its
> information from on Linux machines.
>
> Chris
> --
>

I know this is a python list, but if speed is such an issue you might want
to consider writing in C/C++.  Both would be considerably faster than
python.



> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080416/3b8c5c9b/attachment-0001.html>


More information about the Python-list mailing list