Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to add another task?
#1
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()
Reply
#2
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) .
Reply
#3
Hi snippsat,

Thats example is exactly what i need, thanks alot Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  count certain task in task manager[solved] kucingkembar 2 1,146 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  Schedule a task and render/ use the result of the task in any given time klllmmm 2 2,122 May-04-2021, 10:17 AM
Last Post: klllmmm
  How to create a task/import a task(task scheduler) using python Tyrel 7 3,773 Feb-11-2021, 11:45 AM
Last Post: Tyrel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020