简体   繁体   中英

python whoosh IndexingError when interrupted

This strange error appears after i had interrupted whoosh commit process. When i am trying to commit now i'm getting

  File "/usr/local/lib/python2.7/dist-packages/whoosh/filedb/filewriting.py", line 179, in     _check_state
    raise IndexingError("This writer is closed")
whoosh.writing.IndexingError: This writer is closed

I've tried to reinstall lib, change the index directory but it doesn't work. So how could i repair whoosh?

I think there is no need to "repair whoosh" (or the index).

It might be simply your code that opens a writer, uses it maybe, closes it and then tries to use the closed writer again.

Just always do it like that:

with myindex.writer() as w:
    w.add_document(title=u"First document", content=u"Hello there.")
    w.add_document(title=u"Second document", content=u"This is easy!")

And if you need to add more documents later (outside this "with"-block), open a new writer the same way...

Note: the writer w gets automatically closed when leaving the with-block, that's how a so-called context manager works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM