Как мне запустить 2 процесса одновременно?
Я делаю будильник на питоне и мне нужно запустить 2 процесса. Первый должен выводить окно, а второй запускать звук. process1
и process2
, несмотря на multiprocessing запускаются поочередно, а не одновременно. Вот код:
#import for time
from datetime import datetime
#import for interface
from tkinter import *
#import for parallel use
from multiprocessing import *
#import functions
from alarm_interface import window
from alarm_sound import alarm_sound
#Function that checks valid time
def valid_alarm(val_al):
if int(str(val_al[0:2]))>23 or int(str(val_al[3:5]))>59:
return "Invalid time"
else:
return "Pass"
#Main programm that asks user for title and time for alarm
while True:
print('Title of the alarm clock:',end=' ')
name_of_alarm=input('')
print('Select the desired time. Enter the hour and minute')
print('Hour:',end='')
user_time_hour=int(input()[0:2])
print('Minute:',end='')
user_time_min=int(input()[0:2])
user_time="{:02d}:{:02d}".format(user_time_hour,user_time_min)
#Checking valid time
if valid_alarm(user_time)=="Invalid time":
print(valid_alarm(user_time))
else:
print(("The alarm clock is set to {:02d}:{:02d}").format(user_time_hour,user_time_min))
break
#Main programm that compares current time and user time
while True:
current_time=str(datetime.now().time())[:5]
if current_time==user_time:
print(name_of_alarm)
#multiprocessing
process1=Process(target=alarm_sound())
process2=Process(target=window())
process2.start()
process1.start()
process2.join()
process1.join()
Источник: Stack Overflow на русском