| 1 | n/a | #include <Python.h> |
|---|
| 2 | n/a | #include <stdio.h> |
|---|
| 3 | n/a | |
|---|
| 4 | n/a | void print_subinterp(void) |
|---|
| 5 | 0 | { |
|---|
| 6 | n/a | /* Just output some debug stuff */ |
|---|
| 7 | 0 | PyThreadState *ts = PyThreadState_Get(); |
|---|
| 8 | 0 | printf("interp %p, thread state %p: ", ts->interp, ts); |
|---|
| 9 | 0 | fflush(stdout); |
|---|
| 10 | 0 | PyRun_SimpleString( |
|---|
| 11 | n/a | "import sys;" |
|---|
| 12 | n/a | "print('id(modules) =', id(sys.modules));" |
|---|
| 13 | n/a | "sys.stdout.flush()" |
|---|
| 14 | n/a | ); |
|---|
| 15 | 0 | } |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | int main(int argc, char *argv[]) |
|---|
| 18 | 0 | { |
|---|
| 19 | n/a | PyThreadState *mainstate, *substate; |
|---|
| 20 | n/a | #ifdef WITH_THREAD |
|---|
| 21 | n/a | PyGILState_STATE gilstate; |
|---|
| 22 | n/a | #endif |
|---|
| 23 | n/a | int i, j; |
|---|
| 24 | n/a | |
|---|
| 25 | 0 | for (i=0; i<3; i++) { |
|---|
| 26 | 0 | printf("--- Pass %d ---\n", i); |
|---|
| 27 | n/a | /* HACK: the "./" at front avoids a search along the PATH in |
|---|
| 28 | n/a | Modules/getpath.c */ |
|---|
| 29 | 0 | Py_SetProgramName(L"./_testembed"); |
|---|
| 30 | 0 | Py_Initialize(); |
|---|
| 31 | 0 | mainstate = PyThreadState_Get(); |
|---|
| 32 | n/a | |
|---|
| 33 | n/a | #ifdef WITH_THREAD |
|---|
| 34 | 0 | PyEval_InitThreads(); |
|---|
| 35 | 0 | PyEval_ReleaseThread(mainstate); |
|---|
| 36 | n/a | |
|---|
| 37 | 0 | gilstate = PyGILState_Ensure(); |
|---|
| 38 | n/a | #endif |
|---|
| 39 | 0 | print_subinterp(); |
|---|
| 40 | 0 | PyThreadState_Swap(NULL); |
|---|
| 41 | n/a | |
|---|
| 42 | 0 | for (j=0; j<3; j++) { |
|---|
| 43 | 0 | substate = Py_NewInterpreter(); |
|---|
| 44 | 0 | print_subinterp(); |
|---|
| 45 | 0 | Py_EndInterpreter(substate); |
|---|
| 46 | n/a | } |
|---|
| 47 | n/a | |
|---|
| 48 | 0 | PyThreadState_Swap(mainstate); |
|---|
| 49 | 0 | print_subinterp(); |
|---|
| 50 | n/a | #ifdef WITH_THREAD |
|---|
| 51 | 0 | PyGILState_Release(gilstate); |
|---|
| 52 | n/a | #endif |
|---|
| 53 | n/a | |
|---|
| 54 | 0 | PyEval_RestoreThread(mainstate); |
|---|
| 55 | 0 | Py_Finalize(); |
|---|
| 56 | n/a | } |
|---|
| 57 | 0 | return 0; |
|---|
| 58 | n/a | } |
|---|