python 的thread很有问题呀;
uwsgi如果不开启thread模式,我在程序中创建的daemon线程只在请求中被执行(请求结束就不执行了),一个应用居然能影响到系统层面的thread,这在java是不可能的。看图:
但进程模式:

后台daemon thread不会自动运行。

至少以前uwsgi没有开启thread只靠进程跑慢的原因找到了,async里的线程全堵在哪里没有被执行。
测试代码:
t = DaemonMonitor(queue,checker)
t.setDaemon(True)
t.start()
class DaemonMonitor(threading.Thread):
def __init__(self,queue,checker):
threading.Thread.__init__(self)
self.queue = queue
self.checker = checker
def run(self):
while True:
now = datetime.datetime.now()
print 'daemon check sleep'
sleep(1)
print 'daemon check now+%s'%now

本文探讨了在使用uwsgi服务器时遇到的Python线程问题,特别是在未启用thread模式下,用户自定义的守护线程无法按预期运行的情况。通过对比Java行为,指出这一现象的异常,并附带测试代码及实验结果。
456

被折叠的 条评论
为什么被折叠?



