[Errno 17] File exists: '/home/sandra/Desktop/whoosh/testing/_MAIN_LOCK'
I can't comment on the much else, but this indicates that the index was
left in a locked state, probably because of an error in the middle of
writing. Just delete the _MAIN_LOCK directory.
Cheers,
Matt
On the subject of that, have you considered updating the
ContextManager code in writing.py to clean up after itself more
thoroughly if exceptions occur during commit? i.e.
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type:
self.cancel()
else:
try:
self.commit()
except Exception:
self.cancel() #error during commit -- we should
unlock the index
raise #but still throw an exception
As I've found that sometimes there are errors that occur
during .commit() (more on that in a forthcoming e-mail). This way
releases the lock so that it doesn't require manual deletion later
(and the associated risk of accidentally manually deleting the lock
when there actually is a process writing to it).
I was also wondering if you'd considered raising a custom exception
rather than the rather generic OSError to indicate that the index is
locked, which would make wrapping code cleaner (we could catch say a
LockError, rather than catching all OSErrors, and checking that
the .errno is equal to the error code of 17 for a file already
existing).
i.e In my working copy, I have the following lock() method:
def lock(self, name):
try:
os.mkdir(self._fpath(name))
except OSError, e:
if e.errno == errno.EEXIST:
raise LockError("Could not lock %s as file %s exists" %
(name, self._fpath(name)))
else:
raise
return True
This would make things clearer for users of the library such as Sandra.
(I can provide nice patched for both of these if you want Matt)
Any thoughts on either of these Matt?
Andy
> I was also wondering if you'd considered raising a custom exception
> rather than the rather generic OSError to indicate that the index is
> locked, which would make wrapping code cleaner (we could catch say a
> LockError, rather than catching all OSErrors, and checking that
> the .errno is equal to the error code of 17 for a file already
> existing).
These are both excellent ideas. I'll work on getting them into the next
release.
Thanks, Andy!
Matt
> These are both excellent ideas. I'll work on getting them into the
> next
> release.
>
Great, thanks for that.
While we're there, is there any chance of getting the 2-line change I
posted at http://trac.whoosh.ca/ticket/46 into the next release as well?
Thanks,
Andy.
Yes, sorry about that :)
I've been tied up with other things and with working on a project to
change the posting format that hasn't been going well. Now I've got some
momentum with docs and performance improvements that are pretty
exciting, so I'll try to get back into the groove with releasing updates.
Matt