Where Is The Best Place To Do Initvm And Attachcurrentthread When Using Pylucene In Django
Solution 1:
I never used pylucene in Django, though initVM()
should be called in a file which is pretty much loaded when the Django server starts (settings.py
would be a good place).
About attachCurrentThread
: The question is where are you using the lucene
module. If it is in views.py then of course do it in views.py. Though I think you should not do it on each function call. If you use class-based generic Django views you can save the VM environment in a object specific variable. Did you try it in the global scope of views.py?
Also keep in mind there are always two steps involved when calling attachCurrentThread
:
vm_env = lucene.getVMEnv()
vm_env.attachCurrentThread()
Addition (see comments below):
I think it depends how you import settings in your project. If you just do ìmport settings
in your apps it will load the module more than once. Instead always do from django.conf import settings
. As far as I know your original settings file will then be only loaded once on server startup
Post a Comment for "Where Is The Best Place To Do Initvm And Attachcurrentthread When Using Pylucene In Django"