By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,222 Members | 2,416 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,222 IT Pros & Developers. It's quick & easy.

urgent question, about filesystem-files

P: n/a
i started python programming a few months ago.

now i need the code to understand if a file already opened in
filesystem by another process ?

i looked at docs, howtos, but did not find related info.
note that normal file open/write operations in python, i know it.

i specificly need to know that "is a file already open by some other
process other than python".
Thank you in advance
Apr 10 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
bvidinli wrote:
i started python programming a few months ago.

now i need the code to understand if a file already opened in
filesystem by another process ?

i looked at docs, howtos, but did not find related info.
note that normal file open/write operations in python, i know it.

i specificly need to know that "is a file already open by some other
process other than python".
The pragmatic solution here is to not worry about it and let it be the
user's problem if he does something stupid.

It's OS specific how to get at this information. On Linux, for example
you can call the `fuser` program (if installed; on Ubuntu it's in the
psmisc package). But this will only tell you if the same user has the
file open (or if you're root).

-- Gerhard
Apr 10 '08 #2

P: n/a
bvidinli wrote:
i started python programming a few months ago.

now i need the code to understand if a file already opened in
filesystem by another process ?

i looked at docs, howtos, but did not find related info.
note that normal file open/write operations in python, i know it.

i specificly need to know that "is a file already open by some other
process other than python".
Thank you in advance
This is a OS function. With Linux you use the command lsof (as root). A
Python program can call such a command, but you have to parse the output.
Robert
Apr 10 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.