Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Logging causing OSError and .nfs files

$
0
0

I have this logger.py file:

import loggingfrom logging.handlers import TimedRotatingFileHandlerFORMAT = '%(asctime)s %(message)s'log = logging.getLogger(__name__)log.setLevel(logging.INFO)handler = TimedRotatingFileHandler('/mnt/NFS-drive/debug.log', when='midnight', backupCount=7)handler.setFormatter(logging.Formatter(FORMAT))log.addHandler(handler)

I use it in this countdown module:

import timefrom logger import logdef countdown(minutes=10, callback=None):    seconds = minutes * 60    # Run the countdown loop    while seconds >= 0:        # Calculate remaining minutes and seconds        remaining_minutes = seconds // 60        remaining_seconds = seconds % 60        # Print the remaining minutes and seconds        log.info("Time remaining: {:02d}:{:02d}".format(remaining_minutes, remaining_seconds))        # Sleep for 1 second        time.sleep(1)        # Decrement the seconds        seconds -= 1    if callback:        log.info("Timer finished...")        callback()

Then I run a multithreaded script which writes logs to debug.log. This script runs on multiple machines as well. They all write logs to the same NFS mounted file.

I'm see two issues

Error:

--- Logging error ---Traceback (most recent call last):  File "/usr/lib/python3.10/logging/__init__.py", line 1104, in emit    self.flush()  File "/usr/lib/python3.10/logging/__init__.py", line 1084, in flush    self.stream.flush()OSError: [Errno 116] Stale file handleCall stack:  File "/mnt/nf/myscripts/run.py", line 128, in run    countdown(minutes=5, callback=lambda: log.info("Checking queue for new messages"))  File "/mnt/nf/myscripts/countdown.py", line 14, in countdown    log.info("Time remaining: {:02d}:{:02d}".format(remaining_minutes, remaining_seconds))Message: 'Time remaining: 03:25'Arguments: ()

And I'm seeing all these .nfs files in the directory:enter image description here

Any idea why i'm suddenly seeing this error and getting this files?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>