Apache的prefork模式导致飞信模块多次初始化

RT

自己写的一个模块,封装了一下PyFetion,目的是尽量保持飞信可用,再就是方便点。

在模块初始化的时候创建线程,登录,然后不停的查询数据库看是否有信息要发送。

后来发现很不稳定,看了下log


[Sun Sep 26 19:59:36 2010] [warn] child process 12374 still did not exit, sending a SIGTERM
Error in my_thread_global_end(): 1 threads didn't exit
[Sun Sep 26 19:59:38 2010] [notice] caught SIGTERM, shutting down
[Sun Sep 26 20:02:24 2010] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.5 with Suhosin-Patch mod_ssl/2.2.14 OpenSSL/0.9.8k mod_wsgi/2.8 Python/2.6.5 configured -- resuming normal operations
[Sun Sep 26 20:02:46 2010] [error] <SupervisorThread(SupervisorThread, started 140184746718992)> ('construct...',)
[Sun Sep 26 20:02:49 2010] [error] <SupervisorThread(SupervisorThread, started 140184746718992)> ('login...',)
[Sun Sep 26 20:02:54 2010] [error] <MessageThread(MessageThread, started 140184645531408)> ('message round',)
......
[Sun Sep 26 20:02:59 2010] [error] <SendSMSThread(SendSMSThread, started 140184637138704)> ('nomsg',)
[Sun Sep 26 20:03:04 2010] [error] <SendSMSThread(SendSMSThread, started 140184637138704)> ('nomsg',)
.......
[Sun Sep 26 20:03:24 2010] [error] <SupervisorThread(SupervisorThread, started 140184746718992)> ('construct...',)
[Sun Sep 26 20:03:24 2010] [error] <HeartbeatThread(HeartbeatThread, started 140184721078032)> ('beat~',)
[Sun Sep 26 20:03:24 2010] [error] <SendSMSThread(SendSMSThread, started 140184637138704)> ('nomsg',)
[Sun Sep 26 20:03:24 2010] [error] <HeartbeatThread(HeartbeatThread, started 140184721078032)> ('beat done',)

 

怎么又开始初始化了呢?

 

后来发现是因为apache的prefork模式。在fork之前每个单独的进程都认为那个module没有初始化,于是就初始化了,导致n个进程同时登录。

 

现在在想,到底是把飞信做成webservice,还是干脆改用worker模式。

你可能感兴趣的:(apache,python,webservice,ubuntu,sun)