0

I built a simple wrapper service around a class that reads and queries a Lucene index using pylucene (6.5). I get the following error when running the server:

RuntimeError: attachCurrentThread() must be called first

I assume that the problem stems from the lucene.initVM() statement and I tried moving it in different places. It works if I put it in the request method, but that means I need to load the index with every request.

Is there a better way to do it?

Aleksandar Savkov
  • 2,894
  • 3
  • 24
  • 30
  • Calling lucene.getVMEnv().attachCurrentThread() before handling each request related to Lucene fixed it, https://stackoverflow.com/a/6543987/4917303 – Oriel Cochavi Jan 13 '21 at 20:28

1 Answers1

0

Putting the initialisation statement (in this case the constructor of IndexHandler) in a function with a flask decorator @app.before_first_request solves the problem.

@app.before_first_request
def load_index():
    global index_handler
    index_handler = IndexHandler()
Aleksandar Savkov
  • 2,894
  • 3
  • 24
  • 30