Mercurial > cpython-lru_cache-weakref
view Modules/_testembed.c @ 73323:dad02a080bbc
Improve byte-compilation in packaging to be independent of -O or -B.
The code I fixed to comply with PEP 3147 still had one bug: When run
under python -O, some paths for pyc files would be pyo, because I called
imp.cache_from_source without explicit debug_override argument in some
places, and under -O that would return .pyo (this is well explained in
the imp docs). Now all code (util.byte_compile, build_py, install_lib)
can create .pyo files according to options given by users,
without interference from the calling Python’s own optimize mode.
On a related topic, I also removed the code that prevented byte
compilation under python -B. The rationale is that packaging gives
control over the creation of pyc files to the user with its own explicit
option, and the behavior should not be changed if the calling Python
happens to run with -B for whatever reason. I will argue that this is a
bug fix and ask to be allowed to backport this change to distutils.
Finally, I moved one nugget of information about the --compile and
--optimize options from the source into the doc. It clears up a
misunderstanding that I (and maybe other people) had.
| author | Éric Araujo <merwok@netwok.org> |
|---|---|
| date | Thu, 03 Nov 2011 05:08:28 +0100 |
| parents | 79fcd71d0356 |
| children | 9cd88b39ef62 |
line wrap: on
line source
#include <Python.h> #include <stdio.h> void print_subinterp(void) { /* Just output some debug stuff */ PyThreadState *ts = PyThreadState_Get(); printf("interp %p, thread state %p: ", ts->interp, ts); fflush(stdout); PyRun_SimpleString( "import sys;" "print('id(modules) =', id(sys.modules));" "sys.stdout.flush()" ); } int main(int argc, char *argv[]) { PyThreadState *mainstate, *substate; #ifdef WITH_THREAD PyGILState_STATE gilstate; #endif int i, j; for (i=0; i<3; i++) { printf("--- Pass %d ---\n", i); /* HACK: the "./" at front avoids a search along the PATH in Modules/getpath.c */ Py_SetProgramName(L"./_testembed"); Py_Initialize(); mainstate = PyThreadState_Get(); #ifdef WITH_THREAD PyEval_InitThreads(); PyEval_ReleaseThread(mainstate); gilstate = PyGILState_Ensure(); #endif print_subinterp(); PyThreadState_Swap(NULL); for (j=0; j<3; j++) { substate = Py_NewInterpreter(); print_subinterp(); Py_EndInterpreter(substate); } PyThreadState_Swap(mainstate); print_subinterp(); #ifdef WITH_THREAD PyGILState_Release(gilstate); #endif PyEval_RestoreThread(mainstate); Py_Finalize(); } return 0; }
