fut.result()
, и это дало положительный эффект! Теперь действия с кнопками уже происходят, но все равно лишь после выполнения функции voiceRecognition
, а стоит перед выполнением. После изменений код выглядит так:def someFunc(self, event):
print('Interface change started') #for test
#creates Button_1
#deletes config.Button_2 (from another func)
print('Interface change finished') #for test
with ThreadPoolExecutor(max_workers=5) as executor:
fut = executor.submit(self.voiceRecognition)
def voiceRecognition (self):
print('Voice recognition was started') #for test
r = sr.Recognizer()
with sr.Microphone(device_index=1) as sourse:
audio = r.listen(sourse)
query = r.recognize_google(audio)
print(query.lower())
print('Voice recognition was finished') #for test
Interface change started
Interface change finished
Voice recognition was started
Voice recognition was finished
someButton = wx.Button(self)
self.Bind(wx.EVT_BUTTON, self.someFunc, someButton)
def first(self, event):
pool = ThreadPoolExecutor(max_workers=multiprocessing.cpu_count())
loop = asyncio.get_event_loop()
loop.run_in_executor(pool, second)
def first(self, event):
loop = asyncio.get_event_loop()
loop.run(self.second())
async def second(self):
document = Document()
document.save('test.docx')