I want to make a background process that displays a
subprocess.Popen(viewer + ' ' + file + ' && rm ' + file, shell=True)
subprocess.call() to open the viewer and view the file will exactly do that. Subsequently, run the command to delete the file.
If you want the script to continue while the process is running, use
from threading import Thread import subprocess import os def test(): file = "/path/to/somefile.jpg" subprocess.call(["eog", file]) os.remove(file) Thread(target = test).start() # the print command runs, no matter if the process above is finished or not print("Banana")
This will do exactly what you describe:
eog(viewer), wait for it to finish (close
eog) and remove the file.