views:

247

answers:

2

I am using mod-wsgi with django, and in django I use pylucene to do full text search.

While mod-wsgi is configured to be embedded mode, there is no problem at all. But when mod-wsgi is configured to be daemon mode, the apache just gets stuck, and the browser just keep loading but nothing appears.

Then I identity the problem to be the jcc.initVM(). Here is my wsgi script:

import os, sys, jcc
sys.stderr.write('jcc.initVM\n')
jcc.initVM()
sys.stderr.write('finished jcc.initVM\n')
....

After I restart my apache, and make a request from my browser, I find that /var/log/apache2/error.log only has:

jcc.initVM

Meaning that it gets stuck at the line jcc.initVM(). (If the mod_wsgi is configured as embedded mode, there is no problem.)

And here is my /etc/apache2/sites-available/default:

WSGIDaemonProcess site user=ross group=ross threads=1
WSGIProcessGroup site
WSGIScriptAlias / /home/ross/apache/django.wsgi

<Directory /home/ross/apache/>
  Order deny,allow
  Allow from all
</Directory>

And finally, I find out that in the source code of jcc (jcc.cpp), it hangs at the function:

JNI_CreateJavaVM(&vm, (void **) &vm_env, &vm_args)

How to solve the problem?

Program versions:

libapache2-mod-wsgi 2.3-1
jcc 2.1
python 2.5
Apache 2.2.9-8ubuntu3
Ubuntu 8.10
+1  A: 

Please refer to http://code.google.com/p/modwsgi/issues/detail?id=131 for the discussion details.

In short, the mod_wsgi will block signals for the daemon program, which may make initVM doesn't work. Furthermore according to Andi from jcc, initVM can only be called from the main thread, and it may cause further problem as well.

Therefore I decided to move the search code with initVM() to a totally separate process and solved the problem.

i-freaker
+1  A: 

The fix for this problem was included in mod_wsgi 2.4.

Graham Dumpleton