[mod_python] Output from C functions

Alexis Iglauer aiglauer at iname.com
Mon Oct 30 00:43:49 EST 2000


I'm doing this from inside a cgi script, would that make the solution any
easier?  Seems like a mightily complex way to do a printf :)  I would like
to stay entirely inside C for my loop, for speed purposes.  Can I maybe pass
the file handle of stdout to my function and then write to that?

aei
----- Original Message -----
From: "Gregory Trubetskoy" <grisha at modpython.org>
To: "Alexis Iglauer" <aiglauer at iname.com>
Cc: <mod_python at modpython.org>
Sent: Sunday, October 29, 2000 11:30 PM
Subject: Re: [mod_python] Output from C functions


>
>
> The cgihandler redirects the sys.stdout to the client. Anything that uses
> the real (non python) stdout will just print somewhere just like you
> describe.
>
> If you want to do this in C, you should use the req.write function. Here
> is what a handler written in C might look like (skipping all the regular
> python module stuff. Kids don't try this at home):
>
> #include mod_python.h
>
> static PyObject * handler(PyObject *self, PyObject *args)
> {
> PyObject *r;
> requestobject *req = NULL;
>
> if (!PyArg_ParseTuple(args, "O", &r))
>     return NULL;
>
> req = (requestobject *)PyObject_GetAttrString(r, "_req");
>
> ap_send_http_header(req->request_rec);
> req->header_sent = 1;
>
> ap_table_set(req->request_rec->headers_out, "content-type",
>      "text/plain");
>
> PyObject_CallMethod((PyObject *)req, "write", "s", "Hello World!\n");
>
> return PyInt_FromLong(OK);
> }
>
>
> --
>   Gregory (Grisha) Trubetskoy
>        grisha at modpython.org
>
> On Sun, 29 Oct 2000, Alexis Iglauer wrote:
>
> > I am running a long calculation using a web interface, and am having the
> > problem that the web client times out before the results come back.  I
fixed
> > this by first printing a valid HTTP header and then having the Python
script
> > print a counter, which the web browser picks up and prints - and then
> > doesn't time out.  Works very well.
> >
> > BUT - I have now recoded the central calculation routine in C (all the
> > control/UI stuff is still Python), and placed a printf routine in there
to
> > output the iterations like I did in the Python, but it doesn't get to
the
> > webbrowser.  Any ideas why?  It prints to stdout if I just run the
script
> > from the console, but not if I call it from apache.  Is there some
buffering
> > when calling a C routine?
> >
> > I am using mod_python 2.6.2 and I wrapped the C function using SWIG.
> >
> > Grateful for any pointers.
> >
> > Thanks
> > Alexis
> >
> > _______________________________________________
> > Mod_python mailing list
> > Mod_python at modpython.org
> > http://www.modpython.org/mailman/listinfo/mod_python
> >
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python




More information about the Mod_python mailing list