2011/2/11 ロリータ コンプレックス <[email protected]>:
> here is my wsgi file
> ============================
> import sys, os
> abspath = os.path.dirname(__file__)
> sys.path.append(abspath)
> activate_this = '/var/www/vhosts/newb.in/env-newb.in/bin/
> activate_this.py'
> execfile(activate_this, dict(__file__=activate_this))
> import urlsMap
> urlsMap.urls=initial();
> from newbin.functions import mylogger
> logger = logging.getLogger()
> hdlr = logging.FileHandler('/root/nbi.log')
> formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
> hdlr.setFormatter(formatter)
> logger.addHandler(hdlr)
> logger.setLevel(logging.NOTSET)
> logger.info(urlsMap.urls)
Add lines:
import os
logger.info('PID %d' % os.getpid())
This will log if this is happening in same process or different processes.
Highlight this as Apache/mod_wsgi can run in multi process
configuration and if multiple requests were actually sent, then you
could see them being handled by different processes. Logging PID will
allow you to distinguish.
You might also set:
LogLevel info
in the Apache configuration and it will then log messages showing you
when script files are being loaded into different processes etc.
> def application(environ, start_response):
> status = '200 OK'
> output = '\n'.join(urlsMap.urls)
> response_headers = [('Content-type', 'text/plain'), ('Content-
> Length', str(len(output)))]
> start_response(status, response_headers)
> return urlsMap.urls
> ======================================
> and it seems runing ok~~ with no problem
>
> but i look the log file,it shows
> 2011-02-11 02:02:54,438 INFO [('/v1/{stp}/', <class
> 'nbi.actions.index.act_index.nbi_test1'>)]
> 2011-02-11 02:02:54,438 INFO [('/v1/{stp}/', <class
> 'nbi.actions.index.act_index.nbi_test1'>)].
Apart from possibility of multiple requests occurring again different
processes at same time depending on what is calling this, the more
likely possibility is as described in:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Reloading_In_Embedded_Mode
That is, if using embedded mode and you modify the WSGI script file,
only the script file will be reloaded on the next request and the
process is not restarted. Because of this, if you have code at global
scope within WSGI script file, it will be executed a second (or third,
or fourth ...) time on subsequent reloads of the script. In your case
this would mean that each time the WSGI script file is loaded after a
change, the logger would be register again. Thus the logger can be
registered multiple times and so when message logged it will be logged
multiple times via the registered logger.
In other words, it is the multiple calls to 'logger.addHandler(hdlr)',
one in each WSGI script file reload that is likely the problem.
If you use mod_wsgi daemon mode, ie.,
WSGIDaemonProcess/WSGIProcessGroup, and have WSGI application
delegated to separate daemon mode process then this will not be an
issue as in that case, modification of a WSGI script file cause the
daemon process to be restarted and no problem of code in global scope
of WSGI script acting in cumulative way within context of same
process.
BTW, see further comments about configuration below.
> is it a request can fire wsgi file to run twice ?
> and i httpd.conf is like this
> <VirtualHost *:80>
>
> ServerName localhost
> ServerAlias 127.0.0.1
> DocumentRoot /var/www/vhosts/nbi
> Alias /media/ /var/www/vhosts/nbi/media/
> #WSGIDaemonProcess default processes=1 threads=1
> #WSGIProcessGroup default
Trying uncomment two lines above and see if problem goes away.
> #wsgi.multithread True
> #wsgi.multiprocess False
These two aren't directives, but are the names of variables that come
through in WSGI environ dictionary as indicator of what process/thread
configuration is only. See:
http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading
You also might look at how you can tell if running in daemon mode vs
embedded mode:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Embedded_Mode_Vs_Daemon_Mode
> WSGIScriptAlias /v1/ /var/www/vhosts/nbi/wsgi-scripts/newb.in.wsgi
This line should be:
WSGIScriptAlias /v1 /var/www/vhosts/nbi/wsgi-scripts/newb.in.wsgi
When last argument is a WSGI script file, usually wouldn't have a
trailing slash on URL mount point.
> <Directory /var/www/vhosts/nbi/wsgi-scripts>
> Options ExecCGI
> SetHandler wsgi-script
Don't need the 'SetHandler' line, that is implicitly done by
WSGIScriptAlias when that directive is used.
Technically the 'ExecCGI' option also isn't need and so can drop that
line as well.
> Order allow,deny
> Allow from all
> </Directory>
> </VirtualHost>
>
> Did I Miss Anything?
> any idea? thks
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=en.