2009/11/17 Alex.yu <[email protected]>:
> Sorry for the subject ,it's difficult to describe.Here is the thing:
> I have developed a python extension using c++ ,mainly for querying
> stardict format dictionary. It works fine outside the web framework.
> But problem occurs when I import it and use it within the web
> framework. I have been on this for quite a long time without success.
> I'm using apache 2.2.12 mod_wsgi 2.6 + web.py 0.33 on ubuntu 9.10,
> here is the related code within the web framework:
>
> class Query:
> def GET(self,w):
> if not w:
> return 'query please'
> userdata=web.input(w=w)
> word=urllib.unquote_plus(web.utils.safestr(userdata.w)) #
> sd=stardict.Stardict('/usr/share/dicts') #sd is a c++ object
> wrapped in python
> res_tuple=sd.fuzzySearch('zombie')
> tmp_str=""
> for re in res_tuple: #re also a c++ object wrapped
> in
> python
> tmp_str+=re.bookname+" "+re.exp
> return tmp_str # unexpectedly,tmp_str is still blank
>
> it returns nothing to my browser without any error in the error.log.
> while the following code returns desired result when executed in
> command line or a python file.
>
> sd=stardict.Stardict('/usr/share/dicts')
> res_tuple=sd.fuzzySearch('zombie')
> tmp_str=""
> for re in res_tuple:
> tmp_str+=re.bookname+" "+re.exp
> print tmp_str
>
> isn't it weird ?
>
> the site is publicly unavailable now , more relating information is as
> follows:
>
> part of config file:
> <Directory /someplace/>
> Options Indexes FollowSymLinks MultiViews
> AllowOverride None
> Order allow,deny
> allow from all
> </Directory>
>
> WSGIScriptAlias / /someplace/app.wsgi
>
> <Directory "/usr/lib/cgi-bin">
> AllowOverride None
> Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
> Order allow,deny
> Allow from all
> </Directory>
>
> part of httpd.conf:
> LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
> WSGIRestrictStdin Off #neither works with or without
> WSGIRestrictStdout Off #neither works with or without
>
> for the c extension python module , it depends on glib2.0 (no md5 or
> expat ) and was wrapped to python by swig.
>
> I totally have no idea why it happens. I hope it is not because of
> mod_wsgi or web.py ,otherwise I have to do the nasty job of
> transfering my application to other framework :(
Do each of the following in turn:
1. Add:
WSGIApplicationGroup %{GLOBAL}
to configuration just under WSGIScriptAlias.
This will force main Python interpreter within process to be used.
This can be needed for C extension modules for Python which are not
coded correctly so as to run in secondary sub interpreters. SWIG
generated extensions are known to have issues in this respect,
although normally it causes a deadlock with request not returning.
Restart and retest to see if it makes a difference.
2. Delegate your application to run in daemon mode rather than
embedded mode, this will make it easier to determine what is going
wrong and also make it easier to detect whether problem is caused by
process crashing.
To do this add:
WSGIDaemonProcess mysite display-name=%{GROUP}
WSGIProcessGroup mysite
just under WSGIScriptAlias.
Keep the WSGIApplicationGroup directive from above.
Also ensure that Apache LogLevel is set to 'info' rather than 'warn'.
This will result in mod_wsgi outputing more logging about what it is
doing and so easier to see if processes restarting.
Restart and retest to see if it makes a difference.
If still crashing, capture from the Apache error log ALL messages from
time just before you made request until after all the messages output
from making the request.
Pay special attention to whether you see a message about 'Segmentation Fault'.
Post this messages to the list.
3. Wrap your WSGI application with first logging middleware described in:
http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Tracking_Request_and_Response
This will cause details of request and response to be logged into
Apache error log and can confirm whether the web application is
actually returning anything or whether it is hanging of whether
process is crashing.
Post the messages logged into error log for this.
Based on above may be able to say what is happening and potentially
suggest other things to do if process is crashing.
Graham
--
You received this message because you are subscribed to the Google Groups
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/modwsgi?hl=.