import time
import daemon
import sys
import os
import mig_file
class Test:
def __init__(self):
self.running = False
self.listfiles = []
def run_daemon(self):
pid = str(os.getpid())
pidfile_ = '/DAEMON_TEST/versions/files/daemon.pid'
with open(pidfile_, 'w') as file_:
file_.write(pid)
self.worker()
def worker(self):
while True:
if self.listfiles:
for i in self.listfiles:
self.running = True
"""file operation that read and updates in new output file """
mig_file.main_test(i)
self.listfiles.remove(i)
else:
self.running = False
def adder(self,files):
self.listfiles.append(files)
def main_root(self):
if len(sys.argv) <=4:
if sys.argv[1] == 'stop':
pidfile = '/DAEMON_TEST/versions/files/daemon.pid'
with open(pidfile, 'r') as file:
pid = int(file.read().strip())
os.kill(pid, 15) # Send SIGTERM signal to the process with the given PID
if sys.argv[1] == 'start':
with daemon.DaemonContext():
self.run_daemon()
if sys.argv[1] == 'add':
e1 = sys.argv[2]
self.adder(e1)
if not self.running:
with daemon.DaemonContext():
self.run_daemon()
ob =Test()
ob.main_root()
After starting daemon, when I add multiple files via command line argument one by one it is not completing(file operation in worker function) one after the other rather it goes in round robin fashion. my requirement is completing/processing one file after the other. would be a great help if someone could help me out.