Sigil-Ebook / Sigil

Sigil is a multi-platform EPUB ebook editor
GNU General Public License v3.0
5.96k stars 578 forks source link

[Bug]: Fatal Python error: PyEval_SaveThread: the function must be called with the GIL held, but the GIL is released #716

Closed xiota closed 1 year ago

xiota commented 1 year ago

Bug Description

Fatal Python error: PyEval_SaveThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: unknown

Aborted (core dumped)

Building from a git checkout (590af12a6). Nothing notable during build. Using Python 3.11.3. Configure/build with following:

  mkdir -p build ; cd build
  cmake -G "Unix Makefiles" \
    -D CMAKE_BUILD_TYPE=Release \
    -D USE_SYSTEM_LIBS=1 \
    -D SYSTEM_LIBS_REQUIRED=1 \
    -D INSTALL_BUNDLED_DICTS=0 \
    -D INSTALL_HICOLOR_ICONS=1 \
    -D DISABLE_UPDATE_CHECK=1 \
    -D MATHJAX_DIR=/usr/share/mathjax2 \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -D CMAKE_C_FLAGS:STRING="$CFLAGS" \
    -D CMAKE_CXX_FLAGS:STRING="$CXXFLAGS" \
    -D CMAKE_SKIP_RPATH=ON ..

  make

Platform (OS)

Linux

OS Version / Specifics

Arch

What version of Sigil are you using?

590af12a6

Any backtraces or crash reports

No response

dougmassay commented 1 year ago

I'll take a look at it.

Unrelated, but please note that specifying -D MATHJAX_DIR=/usr/share/mathjax2 does nothing after Sigil v1.9.10. From v1.9.20 on, Sigil requires MathJax3 to properly render MathML in Preview. Sigil will use its own bundled MathJax3 unless -D MATHJAX3_DIR= is used to configure. You must ensure your system is using mathjax 3.2.2+ before debundling.

kevinhendricks commented 1 year ago

My bad. Endif for bundling in EmbeddedPython.cpp should have been earlier so that PyInitialize() or its new equivalent gets called by all platforms (ie. Linux which does not bundle).

So my refactoring refactored out all calls to Initialize Python for Linux.

I am on it.

kevinhendricks commented 1 year ago

Just pushed a "fix" for my refactoring mistake to current master. Please pull from master again and rebuild.
Please let us know if this works. I can not test this change on Linux as I am away from my Linux box for the weekend.

xiota commented 1 year ago

MATHJAX_DIR ... does nothing ... Sigil requires MathJax3 to properly render MathML in Preview.

Thanks for the info. I will take a closer look at MathJax3.

Just pushed a "fix"

Awesome. I'm away from my computer for a while. Will test and respond with results when I get a chance.

xiota commented 1 year ago

Just built and tested. PyEval_SaveThread GIL error is resolved. Thank you.