[Zope] ZPublisher or Bobo and stdout
Dr. Armin Tschammer
Armin.Tschammer@oi42.kwu.siemens.de
Tue, 02 Mar 1999 16:53:07 +0100
Hi,
The followowing problem seems very fundamental to me.
I already did a post to this group to this topic and I got the following
answer:
On Wed, 13 Jan 1999, Dr. Armin Tschammer wrote:
> I publish the following Modul with Bobo:
> Very simple:
>
> hello.py:
>
> import sys, os, time
> import DocumentTemplate
>
> lib=sys.path[0]
> sys.path.append(os.path.join(lib,'DT'))
>
> def hello():
> "Display a greeting"
> # print "rrr"
> X3 = DocumentTemplate.HTMLFile(lib+'/hello.dtml')
> return X3()
> Now, when I make the commentated line print "rrr" active, I get
> Internal Server Error
The "print" goes directly to the webserver, which confused it: it
expects
HTTP headers like "HTTP/1.0 200 Okay".
The "return" sends your data to *Zope*, which then does the header stuff
for you. Same with cookies, content-type, etc.
Summary: dont use 'print', or redirect stdout to a log file.
Now the problem is deeper, what shall I do when I am import C++ Modules
in Python ( extending Python),
and that modules are writing to the stdout via "cout" or "printf", I
have no influence to that.
If I change the stdout via "freopen( "file, "wr", stdout )" or stuff
like that, I have no chance to switch back
to the *real* stdout ( look at the c-faq of comp.lang.c ), and I *have
to* switch back because of the cgi-mechnism,
which uses ZPublisher.
The only the chance to handle stuff like that is to work with two
processes in the Zopemechanism.
A Zopeserver which tells the Zope Client to start a pythonfunction. Now
all stdout happens on the
client and the server listen for a string on a socket ( or something
similar ). Now when
the server gets the string it does all necessary wrapping ( content-type
and so on ), and
send it to the Xserver via its stdout.
Or is there a less complicate solution ?
Thanks in advance
Armin