// pythontest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <C:\Python26\include\Python.h>
BOOL run = true;
int rand_delay = 0;
DWORD WINAPI thrdFun(void * param)
{
for (;run;)
{
rand_delay++;
PyGILState_STATE state;
state = PyGILState_Ensure( );
printf("\nhere00:%d\n", GetCurrentThreadId());
PyRun_SimpleString(
"import time\n"
"print '\\nToday is %s\\n'%(time.ctime(time.time()))\n"
);
Py_BEGIN_ALLOW_THREADS
Sleep(rand_delay%7);
Py_END_ALLOW_THREADS
printf("\n__here:%d\n", GetCurrentThreadId());
PyGILState_Release( state );
}
return 0;
}
int main(int argc, char *argv[])
{
Py_Initialize();
PyEval_InitThreads();
PyEval_ReleaseThread(PyThreadState_Get());
DWORD trd;
int i;
for(i=0; i<4; i++)
{
CreateThread(NULL, 0, thrdFun, NULL, 0, &trd);
}
Sleep(5000);
run = FALSE;
Sleep(7);
PyGILState_Ensure();
Py_Finalize();
return 0;
}