c++ - 在嵌入 Python 解释器的应用程序中调试 tk85.dll 中的问题

标签 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 ??() (??:??)

我什至从哪里开始调试这个问题?它似乎是可重现的。

最佳答案

首先,我告诉你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

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

关于c++ - 在嵌入 Python 解释器的应用程序中调试 tk85.dll 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2513275/

相关文章:

iframe - 将youtube视频播放列表嵌入ebay不能使用iframe或<object?

delphi - 是否可以在 Delphi 可执行应用程序中嵌入并运行 exe 文件?

cordova - 是否可以将本地Web服务器嵌入到phonegap项目中?

c++ - 为什么 std::ofstream 添加额外的#13(换行符)字符?

c++ - 条件断点失败的 GDB Eigen 调试

c++ - 找到cmd.exe文件的位置

python : Downloading file from the link which is implemented with php

c++ - 将每个单词的第一个字符大写 - 帮助发现我的错误

python - 我如何在 python 中使用 pcov 来获取每个参数的错误?

python - numpy 中的多重对数