urgent question, about filesystem-files

B

bvidinli

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
 
G

Gerhard Häring

bvidinli said:
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
 
R

Robert.Spilleboudt

bvidinli said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,113
Latest member
Vinay KumarNevatia
Top