红色多瑙河 发表于 2017-1-10 11:24:40

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

  RT

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

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

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


child process 12374 still did not exit, sending a SIGTERM
Error in my_thread_global_end(): 1 threads didn't exit
caught SIGTERM, shutting down
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
<SupervisorThread(SupervisorThread, started 140184746718992)> ('construct...',)
<SupervisorThread(SupervisorThread, started 140184746718992)> ('login...',)
<MessageThread(MessageThread, started 140184645531408)> ('message round',)
......
<SendSMSThread(SendSMSThread, started 140184637138704)> ('nomsg',)
<SendSMSThread(SendSMSThread, started 140184637138704)> ('nomsg',)
.......
<SupervisorThread(SupervisorThread, started 140184746718992)> ('construct...',)
<HeartbeatThread(HeartbeatThread, started 140184721078032)> ('beat~',)
<SendSMSThread(SendSMSThread, started 140184637138704)> ('nomsg',)
<HeartbeatThread(HeartbeatThread, started 140184721078032)> ('beat done',)
  怎么又开始初始化了呢?
  后来发现是因为apache的prefork模式。在fork之前每个单独的进程都认为那个module没有初始化,于是就初始化了,导致n个进程同时登录。
  现在在想,到底是把飞信做成webservice,还是干脆改用worker模式。
页: [1]
查看完整版本: Apache的prefork模式导致飞信模块多次初始化