Graham Dumpleton
grahamd at dscpl.com.au
Sun Mar 20 19:39:54 EST 2005
vegetax wrote .. > Graham Dumpleton wrote: > > >> - Where do i set a database connection pool to load at server > >> initialization ,so that all request can access it? is the pythonImport > >> directive the best place? where do i set a clean up function for the > >> pool > >> at server finalization ? > > > > Cleanup function registration for stuff that should be done at time of > > child > > termination can only be done with req.server.register_cleanup(). There > > probably should be an apache.register_cleanup() method which would be > > available from a module imported using PythonImport. This would then > be > > the > > best way of doing it. > > > > It seems that the best one could do now is import the module when > > required > > but don't do anything at the time of import which would require a > > cleanup > > function to be registered. Then, when the first handler calls in to the > > actual module, require that the "req" object be passed into the pool, > > with > > those resources which need to be cleaned up later being created then > > with a > > cleanup function being registered through req.server.register_cleanup(). > > > > I have added a bug report suggesting that apache.register_cleanup() be > > added to allow it to be used from module imported using PythonImport. > > But is to problematic to clean resources at request level, i think in the > midtime i will be cleaning up resources like connections with an external > script which i run after apache exits. I perhaps didn't explain it properly or I don't understand what you are saying. >From a request object there are two ways of registering a cleanup function. The first is: req.register_cleanup() The register function in this case will be called when the handler for that specific request is finished. The other which I referenced was: req.server.register_cleanup() This registers a function which will only be called when the Apache process itself terminates. Ie., when one does apachectl stop or restart. Thus, wasn't talking about cleaning up resources at request level. The unfortunate bit was that since apache.register_cleanup() doesn't exist, one has to defer registration of cleanup function for process termination until one has access to req.server, which is at point of first request that needs pool. > > FWIW, in Vampire, when Vampire's module importing mechanism is used a > > stripped down request object is available in the set of global variables > > during import as __req__. Thus in Vampire one could actually register > > a cleanup function during import by using: > > > > __req__.server.register_cleanup(....) > > > > This would save each handler having to pass the req object into a pool > > and > > means one wouldn't have to delay creation of resources which needed the > > cleanup function to be registered. > > Looks like a good solution when the clean up is needed per request,and > is > also posible that the pool component was made by someone else,and cant > take > req as parameter. Again, not talking per request here as am registering cleanup handler via the server object and not the actual request object. > > BTW, have you considered other page templating solutions besides PSP? > > In terms > > of best separation between model, view and controller, or at least > > between the > > HTML that represents a page and the code that populates it, I would > > recommend > > using HTMLTemplate. > > > > http://freespace.virgin.net/hamish.sanderson/htmltemplate.html > > > > Why I prefer it over PSP is that in PSP you are effectively still > > embedding > > Python code in the template itself and to render the template you are > > actually > > executing it, with there being call outs from the template to collect > > data. > > In HTMLTemplate, the template object is distinct, with your controller > > code > > making calls into the template object when desired to set fields within > > it. > > Ie., DOM like but not having the overhead of a DOM because only > > fillable parts > > of the template are indexed. > > > > What this means is that with HTMLTemplate you aren't forced to prepare > > all your > > data up front before filling in the template, instead you can fill it > > in bit > > by bit. > > > > I can supply references to example of using HTMLTemplate from Vampire > > later if > > you are interested. > > Graham > > Thanks for the advice graham,but i dont share the philosophy kind of those > templates engines, first and last it uses its own tag language, i HATE > that. Huh. PSP also defines its own language within HTML so I don't really see the difference. I personally find the PSP syntax more confusing, more complicated and more error prone especially if embedding actual Python code. Please don't confuse HTMLTemplate with systems like TAL and Metal. It is different and much simpler, with the manner in which pages are constructed and then rendered being different as well. > I like psp because it lets you embed python code, so that i can > generate complex dynamic views,but the code inside the psp is only for > content displaying, 100% of the form processing is done by the controler > calling domain object's methods! in extremely exceptional situations the > psp code will have a litle processing or data gathering, but those are > only > exceptions, the key here is that the team respect the rules. > > I work with web designers,you simply cant let them touch the dynamic > parts,those parts tend to be complex,they should work in the static parts > and coordinate with the programmer in charge of the dynamic view > generation,and then plug dynamic and static parts together, in order to > coordinate they MUST have some programming knowledge ,anyway i use > javascript a lot and i dont take a person who doesnt know javascript as > a > web designer.Thats my point of view. When using HTMLTemplate the web designers don't need to touch any Python code at all and thus don't go anywhere near the controller aspects of the application. Because HTMLTemplate is standard XHTML the web designer can even use high level web design tools. All they need to do is add the appropriate namespace designated attributes in the XHTML as per Python coders directions as to what data will be filled in. The web designer can even put in dummy data in the template as place holders so the pages look correct for some set of data when they are designing it, with the dummy content being replaced by the controller code when it runs. Anyway, there is probably no point continuing this particular discussion. As I always find it is always very hard to get someone else to see what you can see, especially when one is using a different framework to bring all the bits together. :-( Graham
|