Python无法启动多个线程

Python无法启动多个线程,python,multithreading,Python,Multithreading,我有以下python代码-创建三个线程。但是在创建第一个线程后,控件似乎不会返回。输出为一个“”,而不是预期的三个“”。辅助功能是否有问题Msglyr是一个内部消息传递库 #!/usr/bin/python import thread import time import Msglyr # Worker thread def worker(num): testchannel = Msglyr.Channel("TEST-ASYNC-ROUTER-DEALER-CHANNEL", Ms

我有以下python代码-创建三个线程。但是在创建第一个线程后,控件似乎不会返回。输出为一个“”,而不是预期的三个“”。辅助功能是否有问题
Msglyr
是一个内部消息传递库

#!/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

我不确定这是否真的是一个答案(无论如何不是你期望的),但我不能做更多。我用你的代码替换了worker

# Worker thread
def worker(num):
    i = 1
    while True :
        print("Thread", num, i);
        i += 1
        time.sleep(3)
一切进展顺利,我可以看到来自3个线程的消息(间隔1秒…),我还看到了3个点。恐怕问题在于
Msglyr