Created
April 22, 2013 12:40
-
-
Save wusuopu/5434609 to your computer and use it in GitHub Desktop.
在Python api中使用线程
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Python.h> | |
#include <pythread.h> | |
static void test(void *s) | |
{ | |
while (1) | |
{ | |
printf("in sub thread\n"); | |
sleep(1); | |
} | |
} | |
static PyObject * | |
thread_test(PyObject *self) | |
{ | |
printf("in thread_test: %ld\n", PyThread_start_new_thread(test, NULL)); | |
Py_RETURN_TRUE; | |
} | |
static PyMethodDef lc_thread_test_methods[] = { | |
{"test", (PyCFunction)thread_test, METH_NOARGS, ""}, | |
{NULL, NULL, 0, NULL} | |
}; | |
PyMODINIT_FUNC initlc_thread_test(void) | |
{ | |
Py_InitModule("lc_thread_test", lc_thread_test_methods); | |
PyEval_InitThreads(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment