ActiveState Powered by ActiveState

ActiveState Community


Tcl process goes to sleep when running as Apache cgi script

Posted by Dave.McIsaac on 2007-09-20 08:13

I have been using Tcl for cgi scripts on an Apache server for several years now. This is all running on an HP-UX workstation (OS Hp_UX 11i). We just migrated the whole thing to an HP A500 class server with dual processors and a LOT more memory (still HP-UX 11i). Now the cgi scripts that are used to pre-load an html form from an existing data set take upwards of 8 minutes to complete. Using the top command shows that tclsh is sleeping. I THINK that the server eventually times out which causes the data to be flushed and sent back to the client. If I wait for this to happen then it seems to work fine from then on. If I log in to the server as a different user I have to wait again. If I attach truss (to monitor the execution steps) to the parent server process it works fine right from the start.
The Tcl script is executing the following procedure:
proc SendHtml {args} {
set outID [open [lindex $args 0] r]
foreach line [split [read -nonewline $outID] \n] {
puts stdout [subst -nobackslashes $line]
}
close $outID
return
}

Has anyone experienced a similar problem or know how to fix this or work around it? This thing is driving me nuts.
Thanks

jeffh | Thu, 2007-09-20 11:36

There is nothing in the description which would explain any kind of change in Tcl's behavior as perceived. Are you sure that something isn't causing the event loops to run and that perhaps you need an explicit exit?

The one change I would make to your script is to try converting the split/read into a while/gets. It sounds like you may be stuck in the read, which would be expecting an EOF and not getting it.

Dave.McIsaac | Fri, 2007-09-21 04:55

Thanks jeffh - I tried this and it made no difference. I'm sorry if I implied that I think the problem is with Tcl. I don't! I think the problem is with the way HP handles communications between processes on their A class machines running HP-UX 11i. I was hoping someone may have encountered the same or a similar problem and had come up with a work-around for it.

Dave.McIsaac | Wed, 2007-09-26 08:55

I think this is fixed. I need to use the mod_cgid module instead of the mod_cgi module in Apache and configure it to use a named socket. This finctionality seems to be explicit to HP-UX. Preliminary testing indicates that it's working fine.

-->