Посмотрите, работает ли это. Я уверен, что есть более простой способ, но это то, что я мог придумать.
from os import listdir
from os.path import isfile, join, abspath
import time
import subprocess
mypath = abspath(__file__)
files_in_folder = [f for f in listdir() if isfile(join(mypath, f))]
# get images
imgs = []
for f in files_in_folder:
_, file_extension = os.path.splitext(f)
if file_extension = ".jpg"
imgs.append(f)
# run loop until keyboard interrupt
try:
while True:
for img in imgs:
viewer = subprocess.Popen(['some_viewer', img])
viewer.terminate()
time.sleep(3)
viewer.kill()
except KeyboardInterrupt:
pass