1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// compile under MingGW/MSYS with:
// gcc program.c -o program.exe -lpython25 -lpthreadGC2
#include <stdio.h>
#include <Python.h>
#include <pthread.h>
int using_thread=0;
void *run_python_console(void *arg);
int main(int argc,char **argv){
//managing command line arguments
if(argc<2){fprintf(stdout,"this program needs arguments. 0 for sequential, 1 for multithreading\n");exit(1);}
using_thread = atoi(argv[1]);
if(using_thread!=0 && using_thread!=1){fprintf(stdout,"Unkown argument. Use 0 for sequential, 1 for multithreading\n");exit(1);}
//if running in sequential mode
if(using_thread==0){
run_python_console("");
}
//if running in threads
else{
pthread_t pth;
pthread_create(&pth,NULL,run_python_console,"");
}
fprintf(stdout,"coucou!\n");fflush(stdout);
return 0;
}
void *run_python_console(void *arg)
{
fprintf(stdout,"Python console loading.....\n");fflush(stdout);
Py_Initialize();
fprintf(stdout,"interactive loop\n");fflush(stdout);
PyRun_InteractiveLoop(stdin,"<stdin>");
fprintf(stdout,"unloading python...\n");fflush(stdout);
if(Py_IsInitialized()==1){Py_Finalize();}
return;
} |
Partager