[Twisted-Python] Process Producer, Request Consumer
So somebody asked on the channel today, "how do I get the output of a system command displayed on my .epy web page?" Basically, the <!--#exec cmd="foo" --> type of thing, if I remember my SSI. Now, given the pieces that are in Twisted, it seems like this should be at most two lines long: 1) create Process 2) designate the web Request as a consumer of the Process. except that I don't know how to do #2 quite so succinctly. Can anyone speak on this subject? - Kevin -- The moon is waxing crescent, 5.7% illuminated, 2.3 days old.
On Sat, 2001-11-17 at 13:26, Kevin Turner wrote:
So somebody asked on the channel today, "how do I get the output of a system command displayed on my .epy web page?" Basically, the <!--#exec cmd="foo" --> type of thing, if I remember my SSI.
Now, given the pieces that are in Twisted, it seems like this should be at most two lines long: 1) create Process 2) designate the web Request as a consumer of the Process.
except that I don't know how to do #2 quite so succinctly. Can anyone speak on this subject?
Your answer is, unfortunately, wrong. From a .epy, the best way to do that is just to run os.popen().read() :). Otherwise, you would be abandoning any further output to that webpage; the Process would take over and close it. This is exactly the sort of situation that web.widgets was designed to remedy. There is unfortunately no widget currently for "process output", but there should be. Patches accepted!. (There should also be one for "relational database query", of course).
-- The moon is waxing crescent, 5.7% illuminated, 2.3 days old.
I'm practically afraid to check -- does Nethack still consider this a "new moon"? :) -- ______ you are in a maze of twisted little applications, all | |_\ remarkably consistent. | | -- glyph lefkowitz, glyph @ twisted matrix . com |_____| http://www.twistedmatrix.com/
On Sat, Nov 17, 2001 at 02:21:40PM -0600, Glyph Lefkowitz wrote:
On Sat, 2001-11-17 at 13:26, Kevin Turner wrote:
it seems like this should be at most two lines long: 1) create Process 2) designate the web Request as a consumer of the Process.
[...] wrong. [...] you would be abandoning any further output to that webpage; the Process would take over and close it.
Well, for the purposes of discussion, because I don't understand how to best use Process, let's say that's acceptable behavour. It's okay if the request is considered finished as soon as the process is. Now, how would I do it? -- The moon is waxing crescent, 7.2% illuminated, 2.5 days old.
From: Kevin Turner
On Sat, Nov 17, 2001 at 02:21:40PM -0600, Glyph Lefkowitz wrote:
On Sat, 2001-11-17 at 13:26, Kevin Turner wrote:
it seems like this should be at most two lines long: 1) create Process 2) designate the web Request as a consumer of the Process.
[...] wrong. [...] you would be abandoning any further output to that webpage; the Process would take over and close it.
Well, for the purposes of discussion, because I don't understand how to best use Process, let's say that's acceptable behavour. It's okay if the request is considered finished as soon as the process is. Now, how would I do it?
Didn't we come to the conclusion on IRC? I think the idea was class WebProcess(process.Process): def __init__(self, request): process.Process.__init__(self) self.request = request def handleChunk(self, data): self.request.write(data) def connectionLost(self): self.write("</body></html>") self.request.finish() process.Process.connectionLost(self) and your .epy would look something like request.write("<html><body>The output of command is:") WebProcess(request) #you probably have to do something more than this.. #register it with the mainloop somehow? Note that this code is guaranteed to be incomplete, but I think that's the general idea. -- <radix> I was drinking tea before this job -- Chris Armstrong <<< radix@twistedmatrix.com >>> http://twistedmatrix.com/users/carmstro.twistd/
On Sun, 2001-11-18 at 01:32, Chris Armstrong wrote:
From: Kevin Turner
Subject: Re: [Twisted-Python] Process Producer, Request Consumer Date: Sat, 17 Nov 2001 18:10:20 -0800 On Sat, Nov 17, 2001 at 02:21:40PM -0600, Glyph Lefkowitz wrote:
On Sat, 2001-11-17 at 13:26, Kevin Turner wrote:
it seems like this should be at most two lines long: 1) create Process 2) designate the web Request as a consumer of the Process.
[...] wrong. [...] you would be abandoning any further output to that webpage; the Process would take over and close it.
Well, for the purposes of discussion, because I don't understand how to best use Process, let's say that's acceptable behavour. It's okay if the request is considered finished as soon as the process is. Now, how would I do it?
Didn't we come to the conclusion on IRC? I think the idea was
[the idea]
and your .epy would look something like
[an epy]
Note that this code is guaranteed to be incomplete, but I think that's the general idea.
That's some creative handwaving. :) Unfortunately, you can't FORGET_IT from an epy, so this isn't possible. If you want to take a look at how a resource does it, take a look at CGIScript in twisted.web.twcgi. In my Copious Free Time, I will attempt to write widgets that do this and database queries. Others are invited to do so as well. Don't use .epy scripts in the future if you can avoid it though; I want to remove them from the distribution sometime in the very near future. -- ______ you are in a maze of twisted little applications, all | |_\ remarkably consistent. | | -- glyph lefkowitz, glyph @ twisted matrix . com |_____| http://www.twistedmatrix.com/
participants (3)
-
Chris Armstrong
-
Glyph Lefkowitz
-
Kevin Turner