简体   繁体   English

python whoosh IndexingError 中断时

[英]python whoosh IndexingError when interrupted

This strange error appears after i had interrupted whoosh commit process.在我中断 whoosh 提交过程后出现这个奇怪的错误。 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.我尝试重新安装 lib,更改索引目录但它不起作用。 So how could i repair whoosh?那么我该如何修复嗖嗖声呢?

I think there is no need to "repair whoosh" (or the index).我认为没有必要“修复 whoosh”(或索引)。

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...如果您稍后需要添加更多文档(在此“with”-块之外),请以相同的方式打开一个新的编写器...

Note: the writer w gets automatically closed when leaving the with-block, that's how a so-called context manager works.注意:writer w 在离开 with-block 时会自动关闭,这就是所谓的上下文管理器的工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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