Forum OpenACS Development: Sourcing of -init.tcl files

Collapse
Posted by Peter Marklund on
When we changed the APM to not have to restart the server after installation of a package we marked -init.tcl files for reload so that they would be loaded into every Tcl interpreter.

The problem with this setup is that most of the -init.tcl files do setup that should only be executed once such as shared memory initialization with nsv and scheduling of procs with ad_schedule_proc. My first idea for a solution was to provide a proc called apm_source_once so that you could have in your -init.tcl file something like:

apm_source_once {
  # Setup shared memory data
  nsv_set ...

  ad_schedule_proc...
}

# Execute code that is not shared across interpreters here
...

The problem with this setup is that I have to add the apm_source_once to just about all contents of all current -init.tcl files and it is error prone as programmers may forget to use it.

I therefore suggest that -init.tcl files are only sourced once upon installation. The worst thing that can happen with this approach is that a package that keeps something in its init file that needs to be sourced in all interpreters cannot be used until the server is restarted.

I have noticed a couple of ad_proc definitions in -init.tcl files but these could easily be moved to -procs.tcl files.

If anybody knows of code in any -init.tcl file that needs to be sourced in every interpreter - let me know.

Thanks!

Peter

Collapse
Posted by Don Baccus on
You might find on closer inspection that at least some of those ad_proc defs are for procs that are submitted to ad_sched*.  I might be wrong but it seems a logical guess.  In this case only the thread doing the *-init.tcl needs to see the proc def.

I think your idea to go back to only sourcing these files once upon startup rather than for each thread is the right thing to do.  Folks with their own custom packages won't have to rewrite them, etc etc.

Thanks for all the work you've done to get all this straightened out, BTW!  The new system of callbacks is really great.

Collapse
Posted by Peter Marklund on
I will give up on my ambition to be able to install packages without server restarts. At least the way OpenACS is used right now, a server restart isn't a problem. People don't install new packages very often.

The stumbling block I ran into is that the procs of a newly installed package wouldn't be available in the interpreter that executes a scheduled procedure setup by the -init.tcl file. I guess if there is a way to load procs into all Tcl interpreters in AOLServer we would have a solution. I'm not spending any more time investigating this right now though.

Collapse
Posted by Mark Aufflick on
My thought is that the interpreter for scheduled procs could have tcl code sourced into it by scheduling a proc to run "now" (specifically without the -thread option to ad_schedule) that sourced the appropriate file.

I think that would work....