具有 MSAA 的 Python 二进制可执行文件在退出时挂起
我正在使用 python comtypes 来访问 IAccessible 接口以供 MSAA(Microsoft Active Accessibility)使用。之后,我们使用 pyinstaller 创建二进制可执行文件,因此问题是在特定平台 - Windows XP x64 上,我们的可执行文件在退出时挂起。在调用进程退出点后,它挂在 ole32.dll 中的 WaitFotMultipleObjectsEx 上 - 它挂在系统代码中,而不是挂在我们的系统代码中,甚至挂在 pyinstaller 引导加载程序中。在调查过程中,我们发现了问题 - 它是在创建许多 IAccessible 对象(即创建子树)时 - 如果您这样做,进程会挂起。想知道其他人是否遇到类似的问题?
PS 在其他操作系统上它工作正常。
I'm using python comtypes to get access to IAccessible interface for MSAA (Microsoft Active Accessibility) usage. After that we create binary executable using pyinstaller, so the problem is that on specific platform - Windows XP x64 our executable hangs on exit. It hangs on WaitFotMultipleObjectsEx in ole32.dll after the process exit point is called - it hangs in system code not in our, or even pyinstaller boot loader. During investigation we located the problem - it is in creating many IAccessible objects (i.e. creating child tree) - if you do it proccess hangs. Wanna know if somebody else faced similar problem?
P.S. On other OSes it works fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前我无法清楚地理解这个问题的根本原因。但解决办法还是找到了,甚至是两个。
第一:添加对 CoUninitialize 函数的额外调用。
不知道为什么它会起作用,因为 comtypes 与 CoInitialize 调用的次数相同。
第二:更改 CoInitializeEx 标志,如果设置了 COINIT_APARTMENTTHREADED(如果未定义 sys.coinit_flags,则为 comtypes 中的默认值) - 进程挂起!所以我选择了COINIT_SPEED_OVER_MEMORY,一切都变得很好!设置它的最简单方法是在导入 comtypes 之前执行以下操作:
I'm not able to clearly understood the root reason of this issue currently. But the solution was found, even two.
First: to add an additional call to CoUninitialize function.
Don't know why it works as the comtypes calls CoUninitialize the same times as CoInitialize.
Second: to change CoInitializeEx flags, cause if COINIT_APARTMENTTHREADED is set (it is default value in comtypes if sys.coinit_flags is not defined) - process hangs! So i've choosen COINIT_SPEED_OVER_MEMORY and everything became fine! The easiest way to set it is to do following before importing comtypes: