0

In Python 2.7 README file, it says

Starting with Python 2.3, the majority of the interpreter can be built into a shared library, which can then be used by the interpreter executable

I want to know the following global variables in pystate.c are compiled into the shared library or the executable file?

static PyInterpreterState *interp_head = NULL;

PyThreadState *_PyThreadState_Current = NULL;

By the way, if such global(static) variables are compiled into shared library, does these states would be shared between different python processes? for example, pCryptGenRandom in random.c

1 Answer 1

1

Both symbols are present in the zero-initialized segment of the shared library:

% nm /usr/lib/x86_64-linux-gnu/libpython2.7_d.so|egrep '(interp_head|_PyThreadState_Current)'
000000000062a230 b interp_head
000000000062a208 B _PyThreadState_Current

The interp_head is a static variable - a variable without external linkage - and is not visible outside the module. _PyThreadState_Current has external linkage and is visible to the program using the shared library:

% objdump -TC /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 | \
   egrep 'interp_head|_PyThreadState_Current'
000000000056d3c0 g    DO .bss   0000000000000008  Base        _PyThreadState_Current

(Only _PyThreadState_Current is listed in the external symbol table).


Each process will have a separate set of global variables; these are not shared among Python processes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.