Hi Scott
By now mod_rivet related code need modifications for your approach to
work. See my comments below
On 6/1/24 14:51, Scott Pitcher wrote:
Hi,
In a tcl source module in my Rivet website I'm launching a thread to
handle periodic database management. I'm having trouble getting that
thread to log to the apache log.
Part of the SetupDatabase proc launches the thread with -
tsv::set [namespace current] Tid [thread::create -preserved [subst {
#
# Give the new thread access to the same website code base and copy
the
# module configuration over.
#
set auto_path "$::auto_path"
namespace eval [namespace current] {
array set Config \{[array get Config]\}
}
[namespace current]::Log "(\[pid\]) New thread created at \[clock
format \[clock seconds\]\]"
if {\[catch "package require Rivet" output ropts\]} {
[namespace current]::Log "(\[pid\]) package require Rivet
failed: \$output"
}
thread::wait ; # DEBUG
requiring package Rivet is not enough. Your example is highlighting a
rigidity, but I don't know if it would make sense to have the whole
command set available to other threads. Let me explain: in mod_rivet the
set up of a Tcl interpreter is done in Rivet_PerInterpInit
(src/mod_rivet_ng/mod_rivet_common.c). From there package Rivet is
loaded calling Tcl_PkgRequire after Rivet_InitCore is called (sets up
most of the command set, ::rivet::inspect included) and other stuff is
prepared. Among these tasks also the interpreter associated data
structure is prepared. This structure carries a reference to the
server_rec pointer required by ::rivet::apache_log_error to work
properly (actually to work at all...)
in other words in rivet/init.tcl (which provides package Rivet) we put
stuff that could easily done in Tcl instead of C but it's kind of a
helper package for Rivet_PerInterpInit.
The Log function was created to capture some logging output and it
simply appends the message into a log file in the website's tmp
directory (adjacent directory to the source files). I can see in this
log file that the new thread is created (line 2) but the "package
require Rivet" fails with the "invalid command name ::rivet::inspect"
(line 3)?
(31279) SetupDatabase: Launching the management thread.
(31279) New thread created at Sat Jun 01 22:26:40 AEST 2024
(31279) package require Rivet failed: invalid command name
"::rivet::inspect"
Can we have rivet commands loaded in other threads? I don't know if 'ts
possible easily and I don't know if it makes sense: many ::rivet
commands have to do with HTTP requests data. What you're outlining is a
monitor thread that works independently of HTTP request
processing....what if you had the monitor threads run in a separate
process and have rivet threads communicate using unix sockets
(https://github.com/cyanogilvie/unix_sockets) and logging using syslog
(https://github.com/mxmanghi/tcl-syslog)?
regards
-- Massimo
A test message from the thread at Sat Jun 01 22:26:40 AEST 2024
A test message from the thread at Sat Jun 01 22:26:41 AEST 2024
scotty@server1:/home/Shares/Engineering/Web/SVP-Technical-Services$
I'm trying to load the Rivet package in this new thread because I want
to use the ::rivet::apache_log_error function. It's rather opaque inside
the thread and I have to examine the sqlite data base operations. It's
certainly not doing maintenance correctly.
Am I do this correctly by trying to package require Rivet?
I know that if I try to call ::rivet::apache_log_error from inside the
thread protected by catch I get:
(32512) New thread created at Sat Jun 01 22:46:31 AEST 2024
(32512) ::rivet::apache_log_error failed: invalid command name
"::rivet::apache_log_error"
Kind regards,
Scott
---------------------------------------------------------------------
To unsubscribe, e-mail: rivet-dev-unsubscr...@tcl.apache.org
For additional commands, e-mail: rivet-dev-h...@tcl.apache.org