С помощью cronjob я запускаю скрипт Python, который сначала проверяет наличие новых файлов.
Код: Выделить всё
def file_to_process():
filePath = "".join([base_url_gpfs, '/*'])
if glob.glob(filePath + "*.xml"):
set_pid_file()
#find oldest xml file and change into corresponding mxf file
xmlToProcess = min(glob.glob(filePath + "*.xml"), key=os.path.getctime)
fileToProcess = xmlToProcess[:-3] + 'wav'
if not os.path.isfile(fileToProcess):
sys.exit(logger.error("{} not found".format(fileToProcess, filePath)))
return xmlToProcess, fileToProcess
else:
os._exit(0)
Код: Выделить всё
def set_pid_file():
if os.path.isfile(pidfile):
logger.info('Process is already running')
os._exit(0)
else:
pid = str(os.getpid())
f = open(pidfile, 'w')
f.write(pid)
В этот момент создается новый экземпляр сценария может начаться снова, когда появится новый файл.
Но, похоже, где-то теряется смысл, когда сценарий запускается несколько раз и происходит сбой. Поэтому я ищу более надежный способ параллельного запуска разных экземпляров одного и того же скрипта.
Подробнее здесь: https://stackoverflow.com/questions/603 ... a-cron-job