Python mod_wsgi应用程序奇怪的行为

Python mod_wsgi应用程序奇怪的行为,python,apache2,mod-wsgi,Python,Apache2,Mod Wsgi,我对Python和Python web应用程序开发相对较新。目前,我正在使用mod_wsgi用Python创建hello world应用程序 这是我的配置 Apache配置 <VirtualHost *:80> ServerName mysite.com DocumentRoot /var/www/mysite WSGIDaemonProcess mysite threads=5 WSGIScriptAlias / /var/www/mysite/m

我对Python和Python web应用程序开发相对较新。目前,我正在使用mod_wsgi用Python创建hello world应用程序

这是我的配置

Apache配置

<VirtualHost *:80>
    ServerName mysite.com
    DocumentRoot /var/www/mysite

    WSGIDaemonProcess mysite threads=5
    WSGIScriptAlias / /var/www/mysite/mysite.wsgi
    WSGIProcessGroup mysite

    <Directory /var/www/mysite>
        WSGIProcessGroup mysite
        WSGIApplicationGroup %{GLOBAL}
        Order deny,allow
        Allow from all
    </Directory>
</VirtualHost>
app.py

import mysite.log as log

logger = log.custom_logger('root')
logger.debug('I am included only once')

class App:

    """ 
    This Class is responsible
    """  
    def __init__(self):
        logger.debug('I will be called only after apache restart')          

    """
    WSGI module will call this function by default    
    """
    def __call__(self, environ, start_response):
        logger.debug('I will be invoked for every request')    

        # Do some stuff here
        start_response(response_state, response_header)          
        return [response]
问题:我无法在
\uuuu init\uuuu
内看到日志,也无法在
app.py
外看到日志

输出

重新启动apache后第一次运行

调试-应用程序-我只包含一次

DEBUG-app-I将仅在apache重新启动后调用

DEBUG-app-I将为每个请求调用

当我在浏览器中刷新页面时

DEBUG-app-I将为每个请求调用


发生了什么事?我知道
\uuuu init\uuuu
不是构造函数,应用程序对象在某处缓存?这是怎么回事。

您的代码甚至与记录的消息不匹配

忽略这一点,模块仅在首次加载时导入一次

在以下情况下,仅调用一次_uinit__u;()

application = mysite.app.APP()
在导入时运行。然后在每个请求上运行_调用_uu()

所以,是的,这些东西被缓存在一个进程中,并在后续请求中重用

注意,不是每个请求都像PHP一样重新加载东西


所以我不确定问题出在哪里。

只是指出,你注意到类名是App并且你正在实例化App吗?谢谢@Bibhas,我已经更新了hanks,我刚刚更新了日志,我是python新手,不确定它将如何呈现。
application = mysite.app.APP()