Форум сайта python.su
пытаюсь связать сишную либу fasctgi с питоном.
#!/usr/bin/python import cpfcgi,os def req(): print (repr(os.environ)) cpfcgi.listen(req)
#include <Python.h> #include <fcgi_stdio.h> static PyObject * fcgi_listen(PyObject *self, PyObject *args) { int num=0; PyObject * fun=NULL; if(!PyArg_ParseTuple(args, "O", &fun)) return(NULL); Py_INCREF(fun); while(FCGI_Accept () >= 0) { printf("Content-type: text/html\r\n\r\nyo<br>%d",num); PyEval_CallObject(fun,NULL); // <- trouble is here num++; } Py_DECREF(fun); return Py_BuildValue("i", 0); } static PyMethodDef cpfcgiMethods[] = { {"listen", fcgi_listen, METH_VARARGS, "listen for fastcgi requests."}, {NULL, NULL, 0, NULL} }; PyMODINIT_FUNC initcpfcgi(void) { (void) Py_InitModule("cpfcgi", cpfcgiMethods); }
Офлайн