python 子线程阻塞主线程_Python子线程阻塞父线程

我有一个需要连续运行的主线程,它应该为它接收到的每个数据创建新的处理器线程,它们也应该连续运行,但是我的问题是,主线程的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线程?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值