python线程等待,等待特定的延迟后如何在python中启动线程

i have functions detection(),timeralg()

while running the timeralg() function, i want detection() to start in parallel after a specific delay.

currently i tried like this

def timeralg(c1,c2,c3,c4):

t=[4,4,4,6,6,20,24,28,32,36,40]#delay determining array

for y in range(0,3):

print 'y is ',y

if((c1>=c2)and(c1>=c3)):

print 'timer1 on for'

x=t[c1]

print x

c1=0

GPIO.output(5,False)#Red1

GPIO.output(13,True)#red2

GPIO.output(12,True)#red3

GPIO.output(7,True)#green1

if(y==2):

t = threading.Thread(detection())

t.start()

print 'processing strtd in from 1'

time.sleep(x-3)

GPIO.output(7,False)

GPIO.output(3,True)#Yellow1

time.sleep(3)

GPIO.output(3,False)#Yellow1

GPIO.output(5,True)#Red1

Unlike this i want 't' to start after a specific delay specified by me.

解决方案

You could wrap detection() as follows:

def delayed_detection():

time.sleep(3)

detection()

Then start your thread with:

t = threading.Thread(delayed_detection)

t.start()

You're not delaying the spawning of the thread, but you are still achieving calling detecton() after three seconds

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值