user3196126 user3196126 - 1 month ago 8
Python Question

Python, doing task 3 times a day while other stuff is happening?

So I have a task that occurs three times a day at a certain time that needs to be executed.

I've set up code that does this using a package called Schedule

https://pypi.python.org/pypi/schedule

What I like about this is I can say, run at 3:00AM every day, or something similar.

However, the issue is, I want my other code to be running at the same time, and not be stuck in the same loop that the Schedule is running in

So right now, it looks something like:

def archerPull():
#insert code for calling archer pull here

with open("LogsForStuffPull.txt", "a") as myfile:
myfile.write("time: " + time.ctime(time.time()))


#this is code for scheduling job to do every day


def schedulingTasks(firstTime, secondTime, thirdTime, fourthTime, fivthTime):

schedule.every().day.at(firstTime).do(archerPull)
schedule.every().day.at(secondTime).do(archerPull)
schedule.every().day.at(thirdTime).do(archerPull)
schedule.every().day.at(fourthTime).do(archerPull)
schedule.every().day.at(fivthTime).do(archerPull)

schedulingTasks("13:46", "13:47", "13:48", "13:49", "13:50")

while True:
schedule.run_pending()
time.sleep(1)


So as you can see, the loop will be True forever, and therefore run the scheduler everyday. But if I want to integrate other stuff with it, will it also be looped forever?

I want the tasks to be indivitual occuring (is asynchronous the word for it)

Please help me out, thanks!

Answer

Yeah, I figured this out the same day I asked this question

I used ap-scheduler to do this, my webapp in flask is running well while the backgrounds tasks I needed work great