Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我围绕一个使用pylucene(6.5) 读取和查询 Lucene 索引的类构建了一个简单的包装服务。运行服务器时出现以下错误:
pylucene
RuntimeError: attachCurrentThread() must be called first
我认为问题源于该lucene.initVM()声明,我尝试将其移动到不同的地方。如果我把它放在请求方法中它会起作用,但这意味着我需要在每个请求中加载索引。
lucene.initVM()
有更好的方法吗?
将初始化语句(在这种情况下是 的构造函数IndexHandler)放在带有flask装饰器的函数中@app.before_first_request可以解决问题。
IndexHandler
flask
@app.before_first_request
@app.before_first_request def load_index(): global index_handler index_handler = IndexHandler()