Check if file is open by another process before open it

Goodmorning I need to check if a file is already open in written or read mode before reopen it by another python code. If I do “os.path.isfile(“namefile”)” the output is yes but I cannot read file until other python process has not finished to write it because I could lose many data.

I would ask if exist a way to check if a file is already opened or not before open it in reading mode by another python code.
Thank you very much
Best regards