python多线程程序运行时 经常突然停止?
1.我以前写的python 程序都能长时间的运行。2.最近写了一个程序,加了一个线程,就经常出现中断的情况。
程序结构如下:
threadProg.py
import threading
import time
class test(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.thread_stop = False
self.con = 0
defrun(self):
global self.con
while(1):
self.con += 1
time.sleep(1)
def stop(self):
self.thread_stop =True
mainProg.py
from threadProg import test
import time
if __name__ == "__main__":
p = test()
p.start()
while(1):
print self.con
time.sleep(1)
....
程序结构大概就是这样,
1.但是在阿里云上运行, 经常是运行了1~2天后,就停止运行了! 也没有报错,
2.还有经常出现主程序停止了,线程程序还在运行?
我的程序结构有问题吗,为什么出现这种情况,我应该怎么改正? 你是如何运行的?
回复 2# reyleon
python mainProg.py 回复 3# yfjelley
你试试 nohup python mainProg.py &> logs & 本帖最后由 yfjelley 于 2014-09-30 15:51 编辑
回复 4# reyleon
这样运行我试过呀: sudo nohup python mainProg.py &
还是会报错呀!
回复 5# yfjelley
你重定向了没? :shock: 回复 6# reyleon
没有重定向,就这样运行的nohup python mainProg.py & 就一个线程? 结构怎么那么奇怪? global self.con
这个是什么意思,没有见过
页:
[1]