most recent 30 from stackoverflow.com2026-05-01T14:45:51Zhttps://stackoverflow.com/feeds/question/37386544https://creativecommons.org/licenses/by-sa/4.0/rdfhttps://stackoverflow.com/q/373865440carlhttps://stackoverflow.com/users/51214482016-05-23T08:49:42Z2016-05-23T09:11:03Z
<p>I get errors like this </p>
<pre><code>return SegmentWriter(self, **kwargs)
File "/usr/local/lib/python2.7/site-packages/whoosh/writing.py", line 502, in __init__
raise LockError
whoosh.index.LockError
</code></pre>
<p>I would like to catch these errors with a try/except statement. So I wrote</p>
<pre><code>try:
do whatever causes the error
except LockError:
print "LockError..."
handle error
</code></pre>
<p>but this leads to a <code>NameError</code>, since <code>LockError</code> is unknown?</p>
<pre><code> except LockError:
NameError: global name 'LockError' is not defined
</code></pre>
<p>how do I handle these Lock errors?</p>
https://stackoverflow.com/questions/37386544/-/37386598#373865984Daniil Ryzhkovhttps://stackoverflow.com/users/12416192016-05-23T08:52:36Z2016-05-23T09:00:06Z<p>First import exception in your namespace. Add this to your module:</p>
<pre><code>from whoosh.index import LockError
</code></pre>