使用 mod_python 运行 jpype 时出现问题
由于 Python 的 urllib 模块太慢,因此我在网站中使用用 JPype 包装的 Java 代码。当我使用 Django Web 服务器测试我的网站时,没有问题。但是,当我将 Web 服务器切换到 apache2 + mod_python 时,出现以下错误。我用谷歌搜索了很多次但找不到答案。错误有什么解决办法吗?
MOD_PYTHON ERROR
ProcessId: 4831
Interpreter: 'localhost'
ServerName: 'localhost'
DocumentRoot: '/home/www/mysite'
URI: '/javamodule.py/'
Location: '/'
Directory: None
Filename: '/home/www/mysite/javamodule.py'
PathInfo: '/'
Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target
result = _execute_target(config, req, object, arg)
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target
result = object(arg)
File "/usr/lib/pymodules/python2.6/django/core/handlers/modpython.py", line 228, in handler
return ModPythonHandler()(req)
File "/usr/lib/pymodules/python2.6/django/core/handlers/modpython.py", line 183, in __call__
os.environ.update(req.subprocess_env)
File "/usr/lib/python2.6/os.py", line 486, in update
self[k] = dict[k]
File "/usr/lib/python2.6/os.py", line 471, in __setitem__
putenv(key, item)
As Python's urllib module is too slow, I'm using Java code wrapped with JPype in my web site. When I tested my web site with Django web server, there was no problem. However when I switched the web server to apache2 + mod_python, following error occurs. I googled many times but couldn't find the answer. Is there any solution to the error?
MOD_PYTHON ERROR
ProcessId: 4831
Interpreter: 'localhost'
ServerName: 'localhost'
DocumentRoot: '/home/www/mysite'
URI: '/javamodule.py/'
Location: '/'
Directory: None
Filename: '/home/www/mysite/javamodule.py'
PathInfo: '/'
Phase: 'PythonHandler'
Handler: 'django.core.handlers.modpython'
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1537, in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1229, in _process_target
result = _execute_target(config, req, object, arg)
File "/usr/lib/python2.6/dist-packages/mod_python/importer.py", line 1128, in _execute_target
result = object(arg)
File "/usr/lib/pymodules/python2.6/django/core/handlers/modpython.py", line 228, in handler
return ModPythonHandler()(req)
File "/usr/lib/pymodules/python2.6/django/core/handlers/modpython.py", line 183, in __call__
os.environ.update(req.subprocess_env)
File "/usr/lib/python2.6/os.py", line 486, in update
self[k] = dict[k]
File "/usr/lib/python2.6/os.py", line 471, in __setitem__
putenv(key, item)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
原始问题的另一个解决方案:寻找其他方法来获得更快的 url 检索。
httplib2 可能已经是一个很好的解决方案:让它工作没有问题,因为它只是一个 python 库,但是对 Keep-Alive 连接的支持可以大大加快速度,另外缓存支持也会有所帮助(但前提是您经常请求相同的 url)。而且它非常容易使用。
如果这还不够:PyCurl,libcurl 的 python 绑定可能是最明显的选择(还有一些包装器可以使 PyCurl 更易于使用,因为 PyCurl 显然有点低级)。
不管怎样,只是说有一些选项不需要java,更容易工作(而且最终可能会更快)
Another solution for your original problem: find other ways to get faster url retrieval.
httplib2 might already be a good solution: no problem to get it working as it's just a python library, but support for Keep-Alive connections can speed up things a lot, plus the caching support will help too (but only if you are often requesting the same url of course). And it's very easy to use.
If that doesn't get you far enought: PyCurl, the python binding for libcurl is probably the most obvious choice (there are also wrappers to make PyCurl easier to use, as PyCurl is apparently a bit low-level).
Anyway, just to say there are options that do not require java, that are easier to get working (and that will be probably end up faster as well)