Python Forum
run 2 commands at the same time ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
run 2 commands at the same time ?
#3
You can start the process with the subprocess.Popen() constructor. No thread is needed as you are running an external process.
import subprocess as sp
 
while True:
    i = (i + 1)
    date = datetime.now().strftime('%d-%m-%y %H-%M-%S')
    print(i, date)
    select = input('Press 1 to send random MP3 \n\r')
    if select == '1':
        with sp.Popen([
            "mpg123", "-o", "alsa:hw:2,0",
            random.choice(TestSound)]) as proc:
            sleep(0.2) # small delay perhaps 
            Check_Voltage()
    else:
        print ('no sound will play , wait for next time! ')
        sleep(5)
Reply


Messages In This Thread
run 2 commands at the same time ? - by korenron - Nov-03-2020, 03:19 PM
RE: run 2 commands at the same time ? - by DeaD_EyE - Nov-03-2020, 03:48 PM
RE: run 2 commands at the same time ? - by Gribouillis - Nov-03-2020, 03:54 PM
RE: run 2 commands at the same time ? - by korenron - Nov-04-2020, 08:00 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020