标题: [问题求助] Python报读慢造成子线程堵塞报错,请教高手?【己解决】 [打印本页]
作者: keshun 时间: 2021-10-21 20:18 标题: Python报读慢造成子线程堵塞报错,请教高手?【己解决】
本帖最后由 keshun 于 2021-11-5 10:47 编辑
- import win32com.client, pythoncom, threading, time
-
- def aa():
- pythoncom.CoInitialize()
- speak = win32com.client.Dispatch('SAPI.SPVOICE')
- speak.Speak(a)
-
- a='1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20'
-
- for i in range(10):
- threading.Thread(target=aa).start()
- for j in range(5):
- time.sleep(1)
- print('{}{}'.format(i,j))
-
- input("关闭窗口")
复制代码
报读慢造成子线程堵塞报错,请教高手?
作者: keshun 时间: 2021-10-22 07:25
本帖最后由 keshun 于 2021-10-22 07:27 编辑
回复 1# keshun
代码运行子线程报读10次,其中5次堵塞报错,最终只报读了5次,主线程正常运行。
以下是第3次报读报错信息,求高手指教??
Exception in thread Thread-3:
Traceback (most recent call last):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
self.run()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "D:\桌面\1.py", line 6, in aa
speak.Speak(a)
File "<COMObject SAPI.SPVOICE>", line 2, in Speak
pywintypes.com_error: (-2147352567, '发生意外。', (0, None, None, None, 0, -2147201018), None)
作者: keshun 时间: 2021-11-5 10:47
- try: speak.Speak('请注意:{}'.format(q4))
- except: pass
- else: pass
复制代码
线程堵塞时自动跳过算了,必竟代码报读集中一起的时候不常出现。
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |