Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python在另一个进程写入时旋转日志文件_Python - Fatal编程技术网

Python在另一个进程写入时旋转日志文件

Python在另一个进程写入时旋转日志文件,python,Python,我有以下python脚本,每1秒将输出写入日志文件,如下所示: python myprocess.py >> mylog.csv def rotate_logs(): # Rotate all logs from *.csv to *.csv.1 for subdir, dirs, files in os.walk(LOG_FILE_DIRECTORY): for filename in files: file_ext = os.path.splitext(

我有以下python脚本,每1秒将输出写入日志文件,如下所示:

python myprocess.py >> mylog.csv
def rotate_logs():
# Rotate all logs from *.csv to *.csv.1
for subdir, dirs, files in os.walk(LOG_FILE_DIRECTORY):
    for filename in files:
        file_ext = os.path.splitext(filename)[1]
        if file_ext == '.1':
            logger.info("Delete %s", os.path.join(subdir, filename))
            os.remove(os.path.join(subdir, filename))
            continue
        if file_ext == '.csv':
            filePath = os.path.join(subdir, filename)  # get the path to your file
            newFilePath = filePath.replace(".csv", ".csv.1"  # create the new name
            logger.info("Changing name from %s to %s", filePath, newFilePath)
            os.rename(filePath, newFilePath) 
我有另一个python脚本
logrotate.py
,每30秒取一次
mylog.csv
文件,将名称更改为
mylog.csv.1
,并将其移动到另一个目录,如下所示:

python myprocess.py >> mylog.csv
def rotate_logs():
# Rotate all logs from *.csv to *.csv.1
for subdir, dirs, files in os.walk(LOG_FILE_DIRECTORY):
    for filename in files:
        file_ext = os.path.splitext(filename)[1]
        if file_ext == '.1':
            logger.info("Delete %s", os.path.join(subdir, filename))
            os.remove(os.path.join(subdir, filename))
            continue
        if file_ext == '.csv':
            filePath = os.path.join(subdir, filename)  # get the path to your file
            newFilePath = filePath.replace(".csv", ".csv.1"  # create the new name
            logger.info("Changing name from %s to %s", filePath, newFilePath)
            os.rename(filePath, newFilePath) 

logrotate.py
旋转日志文件的同时,我可能会错过
myprocess.py
写入日志的情况下的日志?如果是这样,我该如何防止这种情况发生?

你为什么要重新发明轮子?使用