ValueError: set_wakeup_fd only works in main thread
Django 部分版本和Flask部分版本,Python 3.8.1环境下使用asyncio.run()方法会报以下错误:
"POST /tts1 HTTP/1.1" 500 -
Traceback (most recent call last):File "D:\GitHub\Python\src\TextToSpeech\venv\lib\site-packages\flask\app.py", line 2551, in __call__return self.wsgi_app(environ, start_response)File "D:\GitHub\Python\src\TextToSpeech\venv\lib\site-packages\flask\app.py", line 2531, in wsgi_appresponse = self.handle_exception(e)File "D:\GitHub\Python\src\TextToSpeech\venv\lib\site-packages\flask\app.py", line 2528, in wsgi_appresponse = self.full_dispatch_request()File "D:\GitHub\Python\src\TextToSpeech\venv\lib\site-packages\flask\app.py", line 1825, in full_dispatch_requestrv = self.handle_user_exception(e)File "D:\GitHub\Python\src\TextToSpeech\venv\lib\site-packages\flask\app.py", line 1823, in full_dispatch_requestrv = self.dispatch_request()File "D:\GitHub\Python\src\TextToSpeech\venv\lib\site-packages\flask\app.py", line 1799, in dispatch_requestreturn self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)File "D:\GitHub\Python\src\TextToSpeech\main.py", line 102, in text_to_speech1loop.close()File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\asyncio\proactor_events.py", line 679, in closesignal.set_wakeup_fd(-1)
ValueError: set_wakeup_fd only works in main thread
在初始化位置写入以下代码可以解决:
if sys.platform == "win32" and (3, 8, 0) <= sys.version_info < (3, 9, 0):asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())