2013-09-22 1 views
0

일부 라이브러리 (파이썬) 용 서버를 작성하고 있습니다.한 번에 하나의 스레드를 queqe로 시작하십시오.

나는 서버가 그의 루프에서 작동하는 동안 다른 것을하기 위해 1 개의 스레드를 열어주기를 원한다.

이 스레드를 대기열로 제어 중이며 대기열에 반환 값이 없을 때까지 서버에서 다른 스레드를 열지 않으려합니다.

try: 
    #we have a return in the queqe 
    returnValue = threadQueue.get(False) 
    startAnotherThread = True 
except Empty: 
    print "Waiting for return value from thread thread....." 

문이 다른 스레드를 열 경우 다음 startAnotherThread 일부에 말할 것이다 큐의 일부 반환 값이있는 경우.

나는 왜 그것이 작동하지 않는지 알 수 없다.

답변

0

해결 : 서버 루프 전에

초기화 :

# thread queue 
threadQueue = Queue() 

# thread numbering 
threadNumber = 0 

# thread start 
threadCanStart = True 

서버 루프 내부 :

if threadCanStart: 
    myThread(threadNumber, threadQueue).start() 
    threadNumber += 1 
    threadCanStart = False 

try: 
    #we have a return in the quqe 
    returnValue = threadQueue.get(False) 
    print "Queue return: ", returnValue 
    threadCanStart = True 
except Empty: 
    print "Waiting for thread....." 
관련 문제