2
我有以下python代碼 - 創建三個線程。但是,在第一個線程創建後,控件似乎不會回來。輸出結果是一個「。」,而不是三個預期的「。」。工作人員功能有問題嗎? Msglyr
是一個內部消息庫。Python無法啓動多個線程
#!/usr/bin/python
import thread
import time
import Msglyr
# Worker thread
def worker(num):
testchannel = Msglyr.Channel("TEST-ASYNC-ROUTER-DEALER-CHANNEL", Msglyr.mlr.ASYNC_ROUTER_DEALER, Msglyr.mlr.ASYNC_DEALER_WORKER)
testchannel.setEndPoint(Msglyr.mlr.ASYNC_DEALER_WORKER, "inproc://test-pt")
testchannel.setEndPoint(Msglyr.mlr.ASYNC_DEALER_CLIENT, "tcp://127.0.0.1:5558")
while True :
msg = Msglyr.Message()
testchannel.receive(msg)
if msg.getnumParts() > 0:
msg.setPart(msg.getnumParts() - 1, "Worker : " + str(num))
testchannel.send(msg)
# Creating three threads
try:
thread.start_new_thread(worker, (1,))
print '.'
time.sleep(2)
thread.start_new_thread(worker, (2,))
print '.'
time.sleep(2)
thread.start_new_thread(worker, (3,))
print '.'
time.sleep(2)
except:
print "Error: unable to start thread"
print 'Started threads'
while 1:
pass