How to check if a file is already opened (in the same process)
<p>And I'd like to specifically achieve that with the try catch construct.</p>

<p>This <a href="https://stackoverflow.com/questions/6825994/check-if-a-file-is-open-in-python">related question</a> suggests that I can do:</p>

<pre><code>try:
    open(fileName, 'wb+')
except:
    print("File already opened!")
    raise
</code></pre>

<p>However, it doesn't work me. I can open the same file multiple times without any problem:</p>

<pre><code>fileObj1 = open(fileName, 'wb+')
fileObj2 = open(fileName, 'wb+')
</code></pre>

<p>Is it because I have Python 3.5? Or because I'm using <a href="https://www.raspberrypi.org/downloads/raspbian/" rel="noreferrer">Raspbian</a>?</p>

<p>Thanks for the help!</p>