ZPublisher or Bobo and stdout
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
On Tue, 2 Mar 1999, Dr. Armin Tschammer wrote:
Or is there a less complicate solution ?
How about Mr. Creosote. This is a wonderful little utility from Jeff Bauer. It basically an example implementation of socket datagrams... ie. it lets you print out via a socket to a little server program. Its great for debugging Zope/Bobo apps. Here's Mr. Creosote's web page for more info... http://starship.python.net/crew/jbauer/creosote/index.html --- John Eikenberry [jae@kavi.com - http://taos.kavi.com/~jae/] ______________________________________________________________ "A society that will trade a little liberty for a little order will deserve neither and lose both." --B. Franklin
participants (2)
-
Dr. Armin Tschammer -
John Eikenberry