0

我有一个通过 Apache/mod_wsgi/Ladon 运行的 python 脚本的奇怪行为,当从 python shell 运行它时,一切都很好,在一台机器上一切都很好,但在另一台机器上,相同的脚本挂起,似乎它正在无限期地做或等待某事:即从 192.168.xxx.xxx/ws/ 打开页面永远不会结束(浏览器一次又一次地加载,转身,即说)。我找不到发生了什么,将事情记录到 apache 日志中什么也没显示,因为通过 apache/ladon 使用导入的脚本似乎永远不会结束。(并且由于两台机器的配置方式相同,我对此感到头疼:/)

当脚本从文件系统和数据库中加载一些数据时,是否可以无限期地锁定这些资源?

我可以将挂在下面几行之类的东西中的模块包装起来,以确保没有任何锁定吗?实际上我已经尝试这样做,它根本没有改变,但这是我的第一个问题,这样写它是否正确(因为我有点困惑但互斥进程不同)?

[...]
from multiprocessing import Lock
mutex = Lock()

mutex.acquire()
import MyHangingModule
mutex.release()
[...]

是否存在从 apache 提供页面时可能会以无限超时结束的情况?那是 python mod_wsgi/ladon 脚本被 apache 或 ladon 杀死,而某些东西仍在等待被杀死的回复?就像关闭服务器时我得到一些:

[Tue Jul 09 16:07:47 2013] [warn] child process 1676 still did not exit, sending a SIGTERM
[Tue Jul 09 16:07:49 2013] [warn] child process 1676 still did not exit, sending a SIGTERM
[Tue Jul 09 16:07:51 2013] [warn] child process 1676 still did not exit, sending a SIGTERM
[Tue Jul 09 16:07:53 2013] [error] child process 1676 still did not exit, sending a SIGKILL
[Tue Jul 09 16:07:54 2013] [notice] caught SIGTERM, shutting down

(通过mod_status搜索pid,其实是W模式下的处理脚本)

编辑:关于 wsgi,我什么都没有 在 wsgi.conf 中,所有内容都被注释 # 实际上,我从默认的 Debian 安装中安装它。有什么我应该看的吗?还是我显然想念?

另一方面,它也是默认的Debian(实际上配置文件内部没有变化,但专门安装了apache2-mpm-worker):

# worker MPM
<IfModule mpm_worker_module>
    StartServers          2
    MinSpareThreads      25
    MaxSpareThreads      75 
    ThreadLimit          64
    ThreadsPerChild      25
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

的输出/usr/sbin/apache2ctl -l

Compiled in modules:
  core.c
  mod_log_config.c
  mod_logio.c
  worker.c
  http_core.c
  mod_so.c

关于 wsgi 的 mod(不添加WSGIApplicationGroup %{GLOBAL})到wsgi.conf):

<pre>
mod_wsgi.process_group = ['']
mod_wsgi.application_group = ['myserver|/mycfg'] # mycfg is actually the name of the python script while i have replaced the server name for posting here
wsgi.multithread = [True]
</pre>

关于 wsgi 的 mod (添加后WSGIApplicationGroup %{GLOBAL})到wsgi.conf)(因此对于我的其他脚本来说非常慢):

<pre>
mod_wsgi.process_group = ['']
mod_wsgi.application_group = ['']
wsgi.multithread = [True]
</pre>

好吧,如果有帮助,这里是使用可能很慢的 Web 服务进行会话的日志部分:(实际上我希望externalDataLoader.py loaded: 0:00:00.394606 (21941 entries loaded) was shared by every one and then occurs only one. Also i have deactivate all others python handled... can this be that the twomod_wsgi (pid=xxxxx): Attach interpreter ''` 然后可以使用一些资源和无限期地等待而没有任何响应,从而使整个服务器和其他 WS 查询以“子进程不退出”结束?

[Wed Jul 24 10:49:20 2013] [notice] caught SIGTERM, shutting down
[Wed Jul 24 10:49:21 2013] [info] mod_wsgi (pid=11199): Initializing Python.
[Wed Jul 24 10:49:21 2013] [notice] Apache/2.2.16 (Debian) mod_wsgi/3.3 Python/2.6.6 configured -- resuming normal operations
[Wed Jul 24 10:49:21 2013] [info] Server built: Mar  3 2013 11:36:06
[Wed Jul 24 10:49:21 2013] [info] mod_wsgi (pid=11203): Initializing Python.
[Wed Jul 24 10:49:21 2013] [info] mod_wsgi (pid=11199): Attach interpreter ''.
[Wed Jul 24 10:49:21 2013] [info] mod_wsgi (pid=11203): Attach interpreter ''.
[Wed Jul 24 10:49:39 2013] [info] [client 192.168.1.130] mod_wsgi (pid=11199, process='', application=''): Loading WSGI script '/var/www/mywebserver/ws/wshandler.py'., referer: http://192.168.1.5/demo/search.html
[Wed Jul 24 10:49:40 2013] [error] externalDataLoader.py loaded: 0:00:00.394606 (21941 entries loaded)
[Wed Jul 24 10:49:42 2013] [error] WSforSearchInsideExternalData. loaded: 0:00:00.000032.
[Wed Jul 24 10:49:42 2013] [error] searched [test] in [External1]: 0:00:00.026233
[Wed Jul 24 10:49:42 2013] [error] searched [test] in [External2]: 0:00:00.067869
[Wed Jul 24 10:49:43 2013] [error] searched [test] in [External3]: 0:00:00.104222
[Wed Jul 24 10:49:43 2013] [error] searching done for [test]: 0:00:00.104222
[Wed Jul 24 10:49:59 2013] [info] [client 192.168.1.130] mod_wsgi (pid=11203, process='', application=''): Loading WSGI script '/var/www/mywebserver/ws/wshandler.py'., referer: http://192.168.1.5/demo/search.html
[Wed Jul 24 10:50:00 2013] [error] externalDataLoader.py loaded: 0:00:00.384349 (21941 entries loaded)
[Wed Jul 24 10:50:02 2013] [error] WSforSearchInsideExternalData. loaded: 0:00:00.000033.
[Wed Jul 24 10:50:02 2013] [error] searched [abjg] in [External1]: 0:00:00.026000
[Wed Jul 24 10:50:02 2013] [error] searched [abjg] in [External2]: 0:00:00.066215
[Wed Jul 24 10:50:02 2013] [error] searched [abjg] in [External3]: 0:00:00.100293
[Wed Jul 24 10:50:02 2013] [error] searching done for [abjg]: 0:00:00.100293
[Wed Jul 24 10:50:40 2013] [error] searched [abjg] in [External1]: 0:00:00.001513
[Wed Jul 24 10:50:40 2013] [error] searched [abjg] in [External2]: 0:00:00.080266
[Wed Jul 24 10:50:40 2013] [error] searched [abjg] in [External3]: 0:00:00.119280
[Wed Jul 24 10:50:40 2013] [error] searching done for [abjg]: 0:00:00.119280
[Wed Jul 24 10:50:48 2013] [error] searched [abje] in [External1]: 0:00:00.001491
[Wed Jul 24 10:50:48 2013] [error] searched [abje] in [External2]: 0:00:00.079586
[Wed Jul 24 10:50:48 2013] [error] searched [abje] in [External3]: 0:00:00.123212
[Wed Jul 24 10:50:48 2013] [error] searching done for [abje]: 0:00:00.123212
4

1 回答 1

1

查看并尝试以下描述的解决方案:

您可能正在使用无法在子解释器中工作的扩展模块。

简而言之,添加到 Apache 配置中:

WSGIApplicationGroup %{GLOBAL}
于 2013-07-10T03:38:04.277 回答