I'd like to use python schedule library to schedule a large amount of jobs.
All jobs perform the same operations but on a different input.
The inputs are stored in a python list.
The idea is to put each input from the list into a shared queue and then process each one of them in sequence.
Here is an example and my attempt:
import queue
import time
import threading
import schedule
def job(name):
print(name)
def worker_main():
while 1:
(job_func,job_msg) = jobqueue.get()
job_func(job_msg)
jobqueue.task_done()
name = ['jane', 'alice', 'mary']
jobqueue = queue.Queue()
schedule.every(2).seconds.do(jobqueue.put, (job, name))
worker_thread = threading.Thread(target=worker_main)
worker_thread.start()
while 1:
schedule.run_pending()
time.sleep(1)
Unfortunately, this approach run 1 job for all items in the list all together. Anyone has any suggestion? Thank you.