程序不会睡觉

时间:2020-01-24 19:18:13

标签: python time

我试图让我的代码调用user3()10秒钟,然后持续(永远)休眠30秒钟,但它从未休眠。我一直在研究代码,我认为这与在user3()中格式化内容的顺序有关,但是我不确定在哪里。

gramcrawler.py

import instaloader
import time
import os
import pathlib
import requests
import threading
from multiprocessing import Process
L = instaloader.Instaloader(download_comments=False, download_videos=False, download_video_thumbnails=False,
                            save_metadata=False)
data_path = pathlib.Path(os.getcwd())/"data"

def user3(L, data_path):
        #login information
        L.login("********", "********")  # (login)
        file2= open("followers3.txt","r")
        data = ""
        lines = file2.readlines()
        line_count=0

        for line in lines:
            data = line.strip()
            profile = instaloader.Profile.from_username(L.context, data)
            number = profile.followees

            for followee in profile.get_followees():
                    file2 = open("followers3.txt", "a+")
                    allusers = open("allusers.txt", "a+")
                    #username = followees[followee]
                    username = followee.username
                    a = followee.userid
                    file2.write("\n"+ str(username))
                    line_count += 1
                    line_count2+=1
                    allusers.write("\n" + str(username))

                    print(username + " User3")
            if line_count==number:
                f = open('followers3.txt', 'r')
                lines = f.readlines()
                f.close()

                f = open('followers3.txt','w' )
                f.write('\n'.join(lines[1:]))
                f.close()


        #close the text file
            file2.close()
def user3timed():
    while True:
        s = time.time()
        while time.time() < s + 10:
            user3(L,data_path)
        time.sleep(60)

if __name__=='__main__':
    p3 = Process(target=user3timed())
    p3.start()
    p3.join()

followers3.txt

liluzivert

0 个答案:

没有答案