Exemplo n.º 1
0
def tail_polling(filepath, stream=sys.stdout, parent_pid=None):
    """
    Tails a file and outputs the content to the specified stream via polling.
    The pid of the parent process (if provided) is checked to see if the tail process should be
    terminated, in case the parent is hard-killed / segfaults
    """
    with open(filepath, "r") as file:
        for block in iter(lambda: file.read(1024), None):
            if block:
                print(block, end="", file=stream)  # pylint: disable=print-call
            else:
                if pop_captured_interrupt() or (
                        parent_pid
                        and current_process_is_orphaned(parent_pid)):
                    return
                time.sleep(POLLING_INTERVAL)
Exemplo n.º 2
0
 def check_for_interrupts(self) -> None:
     return pop_captured_interrupt()