python 安排多个函数
python schedule multiple functions
我想安排 运行 2 个功能
func1 到 运行 特定持续时间
func2 到 运行 特定持续时间
time1 = 4:20
time2 = 6:20
duration1 = 1 hour
duration2 = 1 hour
def func1():
print("func1") # random function
def func2():
print("func2") # random function
我只是给出了代码的想法,这将有助于解决它...
您可以使用 time
模块中的 time.sleep()
函数,如果您正在寻找的话。
我会尝试满足您的要求...
所以你需要一个代码 运行 func1 在特定的时间和特定的持续时间然后 运行 func2 在特定的时间和特定的持续时间....
据此我将导入 schedule
和 time
。
import schedule
import time
# make sure the time is in correct format....If the time is 4:20, then you must enter 04:20...
time1 = input("When do you want to start func1 ? (format=00:00): ")
# 1 hour = 3600
# 1 hour, 15 mins = 4500
# 1 hour, 30 mins = 5400
# make sure the duration is only in seconds... for 1 hour you must enter 3600
duration1 = input("What will be the duration of func1 ? (format = only seconds): ")
# make sure the time is in correct format if the time is 6:20 then enter 06:20
time2 = input("when do you want to start func2 ? (format=00:00): ")
# make sure the duration is only in seconds... for 1 hour you must enter 3600
duration2 = input("what will be the duration of the func2? (format = only seconds): ")
def func1():
# your func1
print("func1") #example
time.sleep(int(duration1))
def func2():
#your func2
print("func2") #example
time.sleep(int(duration2))
exit()
def looping():
schedule.every().day.at(time2).do(func2)
while True:
schedule.run_pending()
time.sleep(1)
schedule.every().day.at(time1).do(func1)
while True:
looping()
按照您的要求我已经尽力了,希望对您有所帮助...
我想安排 运行 2 个功能
func1 到 运行 特定持续时间 func2 到 运行 特定持续时间
time1 = 4:20
time2 = 6:20
duration1 = 1 hour
duration2 = 1 hour
def func1():
print("func1") # random function
def func2():
print("func2") # random function
我只是给出了代码的想法,这将有助于解决它...
您可以使用 time
模块中的 time.sleep()
函数,如果您正在寻找的话。
我会尝试满足您的要求...
所以你需要一个代码 运行 func1 在特定的时间和特定的持续时间然后 运行 func2 在特定的时间和特定的持续时间....
据此我将导入 schedule
和 time
。
import schedule
import time
# make sure the time is in correct format....If the time is 4:20, then you must enter 04:20...
time1 = input("When do you want to start func1 ? (format=00:00): ")
# 1 hour = 3600
# 1 hour, 15 mins = 4500
# 1 hour, 30 mins = 5400
# make sure the duration is only in seconds... for 1 hour you must enter 3600
duration1 = input("What will be the duration of func1 ? (format = only seconds): ")
# make sure the time is in correct format if the time is 6:20 then enter 06:20
time2 = input("when do you want to start func2 ? (format=00:00): ")
# make sure the duration is only in seconds... for 1 hour you must enter 3600
duration2 = input("what will be the duration of the func2? (format = only seconds): ")
def func1():
# your func1
print("func1") #example
time.sleep(int(duration1))
def func2():
#your func2
print("func2") #example
time.sleep(int(duration2))
exit()
def looping():
schedule.every().day.at(time2).do(func2)
while True:
schedule.run_pending()
time.sleep(1)
schedule.every().day.at(time1).do(func1)
while True:
looping()
按照您的要求我已经尽力了,希望对您有所帮助...