Fix potential OSError when removing log file on FUSE device#1449
Conversation
|
Thanks for the PR. However, it looks to me like something that should be fixed upstream, either in your FUSE implementation or in CPython. If |
|
The problem is that if we add logger with |
I do not know what is causing this on your specific filesystem. If you cannot pinpoint exactly the source of error, but are confident from loguru import logger
import gzip
import shutil
import os
def compression(file_path):
gz_path = file_path + ".gz"
with open(file_path, "rb") as f_in:
with gzip.open(gz_path, "wb") as f_out:
shutil.copyfileobj(f_in, f_out)
# In some cases when we write logs to directory mounted with
# FUSE device using OSS (or AWS S3) + Fluid, here we may encounter:
# OSError: [Errno 34] Numerical result out of range,
# but the log file is removed successfully actually
try:
os.remove(file_path)
except OSError:
pass
logger.remove()
logger.add("file.log", compression=compression)
logger.info("Hello, World!")Note: make sure your program isn't inadvertently logging to the same file from multiple child process at the same time. This is a known source of errors while using |
OK, Thanks, I will try soon. |
|
Related PR: datajuicer/data-juicer#980 |
In some cases when we write logs to directory mounted with FUSE device using OSS (or AWS S3) + Fluid, here we may encounter: OSError: [Errno 34] Numerical result out of range, but the log file is removed successfully actually.