Как запустить две функции одновременно?
@bot.message_handler(content_types=['text'])
def timer(message): ### Эту и следующую нужно вместе запустить
msg = bot.send_message(chat_id=message.chat.id, text='START')
time.sleep(1)
msg_id = msg.message_id
time_s = 5
for t in range(time_s, 0, -1):
bot.edit_message_text(chat_id=message.chat.id, message_id=msg_id, text=f'Wait...{t} секунд')
time.sleep(1)
bot.edit_message_text(chat_id=message.chat.id, message_id=msg_id, text='END')
def voice(message):
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
send_notification(message)
print("* done recording")
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
bot.send_audio(message.chat.id, open('output.wav', 'rb'))
time.sleep(1)
os.remove('output.wav')
Я пробывал:
from multiprocessing import Process
def func1(message):
time.sleep(5)
bot.send_message(message.chat.id, '1 - Функция.')
def func2(message):
time.sleep(5)
bot.send_message(message.chat.id, '2 - Функция.')
if __name__=='__main__':
p1 = Process(target = func1)
p1.start()
p2 = Process(target = func2)
p2.start()
Но в if__name__ нужно указать аргументы message, когда указываю то ошибка 'message is not defiend'.