我的python线程似乎冻结了raspberry pi

时间:2016-09-06 06:51:38

标签: python multithreading raspberry-pi nohup youtube-dl

我写了这个python代码,用我的Raspian连续运行我的Raspian: 'nohup python code.py& “

它的工作时间有点像(从5分钟到60分钟),然后似乎冻结我的pi(我还没有连接显示器,但是它会杀死远程连接并且绿色开启LED停止),

,当它们完成时,不应该一次启动多于6个线程,但它可能仍会超载

我的问题是,我做错了什么或者我可以针对性能进行优化吗?

它会在“nohup-document”中写入大量文本,这会导致问题吗?

#This downloads the link using "youtube-dl"
def Download(link):
    command = "youtube-dl " + link
    call(command.split(), shell=False)

#This check if the link exist in document, else writes it to the document and start downloading it
def CheckAndDL2(DLlink):
    if not DLlink in open('usedlinks.txt').read():
        f = open('usedlinks.txt', 'a')
        f.write(DLlink + "\n")
        f.close()
        try:
            thread.start_new_thread(Download, (DLlink,))
        except:
            print("unable to start thread1")

while 1:
    #getLinks will update links[] with new urls 
    getLinks(myurl) 
    CheckAndDL2(links[1])
    time.sleep(10)
    CheckAndDL2(links[2])
    time.sleep(10)
    CheckAndDL2(links[3])
    print('Loop done')
    links = []
    time.sleep(120)

1 个答案:

答案 0 :(得分:1)

愚蠢的我!我使用 powersupply ,电流输出为0.45mA。我改为1A并且没有问题!