Embedding Python in C, linking fails with undefined reference to `Py_Initialize’

Also add –embed to python3-config On Ubuntu 20.04, Python 3.8, I also needed to pass –embed to python3-config as in: gcc -std=c99 -ggdb3 -O0 -pedantic-errors -Wall -Wextra \ -fpie $(python3-config –cflags –embed) -o ‘eval.out’ \ ‘eval.c’ $(python3-config –embed –ldflags) otherwise -lpython3.8 is not added which leads to missing definitions. This is my test program: eval.c … Read more

PyEval_InitThreads in Python 3: How/when to call it? (the saga continues ad nauseam)

Your understanding is correct: invoking PyEval_InitThreads does, among other things, acquire the GIL. In a correctly written Python/C application, this is not an issue because the GIL will be unlocked in time, either automatically or manually. If the main thread goes on to run Python code, there is nothing special to do, because Python interpreter … Read more