In case your process produces significant amounts of output that you don’t want to buffer in memory, you should redirect the output to the electronic trash can:
subprocess.run(["pdflatex", filename], stdout=subprocess.DEVNULL)
The special value DEVNULL indicates that the output is sent to the appropriate null device of your operating system (/dev/null on most OSes, nul on the other one).