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