当 mod_wsgi 配置为守护进程模式时,jcc.initVM() 不会返回
我将 mod-wsgi 与 django 一起使用,在 django 中我使用 pylucene 进行全文搜索。
而mod-wsgi配置为嵌入模式时,完全没有问题。 但是当mod-wsgi配置为守护进程模式时,apache就会卡住, 浏览器只是继续加载,但什么也没有出现。
然后我确定问题出在 jcc.initVM() 上。 这是我的 wsgi 脚本:
import os, sys, jcc
sys.stderr.write('jcc.initVM\n')
jcc.initVM()
sys.stderr.write('finished jcc.initVM\n')
....
重新启动 apache 并从浏览器发出请求后,我发现 /var/log/apache2/error.log 只有:
jcc.initVM
意味着它卡在 jcc.initVM() 行。 (如果mod_wsgi配置为嵌入模式,则没有问题。)
这是我的/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>
最后,我发现在jcc(jcc.cpp)的源代码中,它挂在函数上:
JNI_CreateJavaVM(&vm, (void **) &vm_env, &vm_args)
如何解决问题?
程序版本:
libapache2-mod-wsgi 2.3-1
jcc 2.1
python 2.5
Apache 2.2.9-8ubuntu3
Ubuntu 8.10
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
mod_wsgi 2.4 中包含此问题的修复。
The fix for this problem was included in mod_wsgi 2.4.
请参阅 http://code.google.com/p/modwsgi /issues/detail?id=131 查看讨论详情。
简而言之,
mod_wsgi 会阻塞守护程序的信号,这可能会使 initVM 无法工作。 此外根据
来自jcc的Andi,initVM只能从主线程调用,并且它也可能会导致进一步的问题。
因此,我决定将 initVM() 的搜索代码移至完全独立的进程并解决了问题。
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.