首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >thread.start_new_thread不工作

thread.start_new_thread不工作
EN

Stack Overflow用户
提问于 2014-12-14 23:18:05
回答 1查看 2K关注 0票数 0

我试图使这些GPIO端口同时打开和关闭,但在RPi上有不同的时间间隔。我可以运行其中的一个循环,它工作,但当我带来线程,它没有。

代码语言:javascript
复制
import RPi.GPIO as GPIO  
from time import sleep  
import thread

GPIO.setmode(GPIO.BOARD)  

GPIO.setup(11, GPIO.OUT)  
GPIO.setup(13, GPIO.OUT)  
GPIO.setup(15, GPIO.OUT)  

def fast():  
    while True:  
        GPIO.output(11, True)  
        sleep(.02)  
        GPIO.output(11, False)  
        sleep(.02)  

def med():
    while True:
        GPIO.output(13, True)
        sleep(.2)
        GPIO.output(13, False)
        sleep(.2)

def slow():
    while True:
        GPIO.output(15, True)
        sleep(2)
        GPIO.output(15, False)
        sleep(2)

thread.start_new_thread(fast,())
thread.start_new_thread(med,())
thread.start_new_thread(slow,())
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-12-14 23:24:03

这是因为没有主程序/循环。您的代码启动了这些线程,但随后它将结束代码并退出运行python的进程,从而杀死线程。所以,可以在底部添加一个raw_input("Press enter to exit")

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27475268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档