urgent question, about filesystem-files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bvidinli

    urgent question, about filesystem-files

    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
  • =?ISO-8859-1?Q?Gerhard_H=E4ring?=

    #2
    Re: urgent question, about filesystem-files

    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

    Comment

    • Robert.Spilleboudt

      #3
      Re: urgent question, about filesystem-files

      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

      Comment

      Working...