You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.3 KiB

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