我有一个需要连续运行的主线程,它应该为它接收到的每个数据创建新的处理器线程,它们也应该连续运行,但是我的问题是,主线程的run函数只运行一次,子线程在主线程的运行中阻塞了while。在import threading
threads = []
class MainThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
#some functions here
def run(self):
while True:
print "main"
#do some stuff
data = ""
client = Client()
if data == "something":
c = 0
found = False
while not found and c
if threads[c].client == client:
threads[c].doSomeStuff(data)
found = True
if not found:
DataHandler(data, client)
class DataHandler(threading.Thread):
def __init__(self, data, client):
threading.Thread.__init__(self)
self.data = data
self.client = client
global threads
threads.append(self)
def doSomeStuff(self, data):
self.data = data
#some IO and networking stuff
#some functions here
def run(self):
while True:
if data is not None:
print "data"
#do some stuff with data
MainThread().start()
我的输出是:main
data
data
data
.
.
.
如何启动一个与MainThread并行的DataHandler线程?在