Jun-24-2022, 12:29 PM
I tried to make a program to autocompile a LaTeX document on Linux Mint whenever the file changes. My effort is as follows:
import subprocess import sys import time from datetime import datetime # This function compiles the document. def execute(command): err = subprocess.STDOUT a = subprocess.check_call(command, stdout=subprocess.DEVNULL, stderr=err) return a modified = datetime.now() print(modified) compiled_once = False while True: time.sleep(1) try: execute(['pdflatex', '-interaction=nonstopmode', '/home/user/a.tex']) print('File okay.') except subprocess.CalledProcessError: print('error')I think it takes very high CPU usage, and thought that sleep(1) will reduce usage as the document won't be compiled too often. How can I reduce the usage?