![]() |
for loop just work one - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: for loop just work one (/thread-15490.html) |
for loop just work one - Faruk - Jan-19-2019 Hello guys. I have a python script for run omxplayer. My purpose this: I have four .mp4 file. I want run these one by one. This fr loop in my script just work one time. How can I fix this? #!/usr/bin/env python #-*- coding: utf-8 -*- import glob import os import subprocess videolist=[] uzunluk=0 video_no=[] videolist=glob.glob('/media/pi/FLASH/playlist/*.mp4') videolist=videolist+glob.glob('/media/pi/FLASH/playlist/*.MP4') uzunluk=len(videolist) for i in xrange(0,uzunluk,1): videoproc=subprocess.Popen(['omxplayer','--win', '0,440,480,800', videolist[i]],stdin=subprocess.PIPE, shell=False) print videolist[i] I solved problem. Just wait subprocess until finish. RE: for loop just work one - Larz60+ - Jan-19-2019 untested: remove line 15-18 and change line 16 to: for video in videolist: videoproc=subprocess.Popen(['omxplayer','--win', '0,440,480,800', video, stdin=subprocess.PIPE, shell=False) print videobut my guess is that this is going to play all three without delay. since you are running as sub-process, you need to store running time in list (use tuples or embedded list), like: videolist = [[time, mp4],[time, mp4]]) and delay between submissions. |