How to add another task? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to add another task? (/thread-35443.html) |
How to add another task? - Makada - Nov-03-2021 Hi, i have to code below working just fine, but i dont knnow how to add the same task (with other .dat file) with a 10 minute interval within this code. with the kindest regards. import time import schedule #starttime=time.time() def task(): #Input_file: "C:\\Campbellsci\\LoggerNet\\CR1000_Table1.dat" #Output_file: "C:\\Users\\Makada\\Desktop\\CR1000_Table1 - kopie.dat" while True: """ Not to append duplicate data to output file""" existingLines = set(line.strip() for line in open("C:\\Users\\Makada\\Desktop\\CR1000_Mburg_Data_ONEMIN.dat")) outfile = open("C:\\Users\\Makada\\Desktop\\CR1000_Mburg_Data_ONEMIN.dat", "a+") for content in open("C:\\Campbellsci\\LoggerNet\\CR1000_Mburg_Data_ONEMIN.dat", "r"): if content.strip() not in existingLines: # to void duplicate lines outfile.write(content) existingLines.add(content) outfile.close() schedule.every().minute.at(":01").do(task) while True: schedule.run_pending() time.sleep(1) refresh() RE: How to add another task? - snippsat - Nov-03-2021 Can use threading to start two task,so they do not block each other. Example. import time, os import schedule import threading def task_1(): print('Task 1 start') def task_2(): print('Task 2 start') def run_threaded(job_func): job_thread = threading.Thread(target=job_func) job_thread.start() if __name__ == '__main__': schedule.every(10).seconds.do(run_threaded, task_1) schedule.every(20).seconds.do(run_threaded, task_2) while True: schedule.run_pending() time.sleep(1)If need to check that first that task-1 has done something then start task-2,look at this Thread So this do check that a process is running if not start it,can be done similar in same way to check a file or something else in task-1(then start schedule for task-2) . RE: How to add another task? - Makada - Nov-03-2021 Hi snippsat, Thats example is exactly what i need, thanks alot |