+ -
当前位置:首页 → 问答吧 → python编写的一个多线程程序,要求死循环执行多线程创建的线程,但是程序执行到一定程度后就在其中一个线程中执行出不来了,请问大家问题出在哪儿呢?万急呀,谢谢

python编写的一个多线程程序,要求死循环执行多线程创建的线程,但是程序执行到一定程度后就在其中一个线程中执行出不来了,请问大家问题出在哪儿呢?万急呀,谢谢

时间:2010-10-23

来源:互联网

python编写的一个多线程程序,要求死循环无限制的执行多线程创建的线程,但是程序执行到一定时间后就在其中一个线程中执行永远也出不来了,请问大家问题出在哪儿呢?万急呀,谢谢

import threading 
import run_sh 
import time
from ccManager import cc_manager
import ccManager
import sys
import groupCommunicationDom0

MulticasDom0=groupCommunicationDom0.MulticasDom0()

# Thread class two
class startup(threading.Thread):  
  def __init__(self):  
  threading.Thread.__init__(self)
  self.lock = threading.Lock() 
   
  def run(self):
  self.lock.acquire()
  run_sh.start()
  self.lock.release()
  time.sleep(1)  

# Thread class three
class resumeTolerate(threading.Thread):  
  def __init__(self):  
  threading.Thread.__init__(self)
  self.lock = threading.Lock() 
   
  def run(self):
  self.lock.acquire()
  run_sh.resumeF()
  self.lock.release()  
  time.sleep(1) 

# Thread class four
class groupCommunDom0(threading.Thread):  
  def __init__(self):  
  threading.Thread.__init__(self)
  self.lock = threading.Lock() 
   
  def run(self):
  self.lock.acquire()
  MulticasDom0.run() 
  self.lock.release()  
  time.sleep(1) 
   
# Thread class five
class suspendTolerate(threading.Thread):  
  def __init__(self):  
  threading.Thread.__init__(self)
  self.lock = threading.Lock()
   
  def run(self):
  self.lock.acquire()
  run_sh.suspendF()
  self.lock.release()  
  time.sleep(1) 

def test(): 
  listthread = []
  #分别创建线程放在列表中统一执行 
  #Creating thread
  threadtwo=startup()
  listthread.append(threadtwo)
   
  threadthree=resumeTolerate()
  listthread.append(threadthree) 
   
  threadfour=groupCommunDom0()
  listthread.append(threadfour) 
   
  threadfive=suspendTolerate()
  listthread.append(threadfive)  

  #统一一起执行线程
  for threadnum in listthread:
  threadnum.start() 

if __name__=='__main__': 
  while True:
  test()

作者: romeany   发布时间: 2010-10-23

望python高手或者其他熟悉多线程编程的高手指点下,谢谢啊

作者: romeany   发布时间: 2010-10-24

突然想起用队列应该能解决这个问题,试一试吧

作者: romeany   发布时间: 2010-10-24