INNER CODE UNIT · Python

follow

lebinh/ngxtop · ngxtop/ngxtop.py:125

def follow(the_file):
    """
    Follow a given file and yield new lines when they are available, like `tail -f`.
    Handles log rotation by detecting inode changes and file size resets.
    """
    f = None
    current_inode = None
    current_size = 0
    retry_count = 0
    max_retries = 5
    
    try:
        while True:
            # Check if we need to (re)open the file
            if f is None or _should_reopen_file(the_file, current_inode, current_size) or _check_rotation_signal():
                if f is not None:
                    f.close()
                    if _check_rotation_signal():

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…