我的 C++ 应用程序嵌入了 Python 解释器,但在关闭时似乎遇到了一些问题。在主窗口关闭后,我得到一个段错误(这是 Windows,但无论如何我们都会称它为段错误)。堆栈跟踪如下:
#0 102AD580 tk85!Tk_MainWindow() (C:\Users\... 1.3\bin\Debug\lib\tk85.dll:??)
#1 103082DD tk85!XSetStipple() (C:\Users\... 1.3\bin\Debug\lib\tk85.dll:??)
#2 102214A3 ??() (C:\Users\...1.3\bin\Debug\lib\tk85.dll:??)
#3 10220000 ??() (??:??)
#4 00000000 ??() (??:??)
我什至从哪里开始调试这个问题?它似乎是可重现的。
最佳答案
首先,我告诉你I identified race conditions in Python's Tkinter when used with nonthreaded Tcl/Tk (Py2 is shipped with that) and proposed a fix .我不确定我修复了所有可能的竞争条件,但我确实修复了我遇到的所有问题。
现在,为了能够调试 Tcl/Tk 问题,您需要使用调试版本的 Tcl/Tk 构建 Python 并将其嵌入。这应该使您能够在调试器中查看 tk*.dll
并查看问题所在。
获取您的 Python 版本的源代码并进行以下更改:
--- a/PCbuild/prepare_tcltk.bat +++ b/PCbuild/prepare_tcltk.bat @@ -46,10 +46,10 @@ rem if ERRORLEVEL 1 (echo Cannot locate python.exe on PATH or as PYTHON variable call "%PCBUILD%\get_externals.bat" --tkinter-src %ORG_SETTING% -%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Release /p:Platform=Win32 -%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Release /p:Platform=Win32 -%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Release /p:Platform=Win32 +%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Debug /p:Platform=Win32 +%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Debug /p:Platform=Win32 +%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Debug /p:Platform=Win32 -%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Release /p:Platform=x64 -%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Release /p:Platform=x64 -%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Release /p:Platform=x64 +%MSBUILD% "%PCBUILD%\tcl.vcxproj" /p:Configuration=Debug /p:Platform=x64 +%MSBUILD% "%PCBUILD%\tk.vcxproj" /p:Configuration=Debug /p:Platform=x64 +%MSBUILD% "%PCBUILD%\tix.vcxproj" /p:Configuration=Debug /p:Platform=x64
从 VS 命令提示符运行
PCBuild\prepare_tcltk.bat
以从源代码下载和构建 Tcl/Tk- 请注意 Tk (and Tix) can't be built with recent versions of WinSDK and will need to be patched .所以运行
.bat
(它会失败),修补下载的源代码并再次运行它。
- 请注意 Tk (and Tix) can't be built with recent versions of WinSDK and will need to be patched .所以运行
现在像往常一样构建一个调试 Python(
PCBuild\readme.txt
有说明)。
关于c++ - 在嵌入 Python 解释器的应用程序中调试 tk85.dll 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2513275/