关闭嵌入Python解释器的应用程序时tk85.dll出现问题

Nat*_*man 22 c++ python embed tkinter

我的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 ??() (??:??)
Run Code Online (Sandbox Code Playgroud)

我甚至会在哪里开始调试这个问题?它似乎是可重复的.

iva*_*eev 1

首先,我让您知道,当与非线程 Tcl/Tk(Py2 附带)一起使用时,我在 Python 的 Tkinter 中识别了竞争条件,并提出了修复方案。我不确定我是否修复了所有可能的竞争条件,但我确实修复了我遇到的所有问题。

现在,为了能够调试 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
    
    Run Code Online (Sandbox Code Playgroud)
  • PCBuild\prepare_tcltk.bat从 VS 命令提示符运行以从源代码下载并构建 Tcl/Tk

  • 现在像平常一样构建一个调试Python(PCBuild\readme.txt有说明)。