[Twisted-Python] Example: Accessing a database from a Resource
mario at ruggier.org
Fri Jan 31 05:56:03 EST 2003
Hi, thanks for the example. Just a couple of comments:
Your doc string for the resource-db exalple:
Example: Making database calls from a Resource.
One of the most common web development tasks involves connecting to a
database, retrieving some data, formatting it as HTML, and returning
it to a web browser. There are two primary means of accomplishing
this task within the Twisted framework, either via twisted.enterprise
(the preferred method), or via twisted.internet.threads.
This example demonstrates the second approach; this is mostly useful
in cases where you need something "quick and dirty", or where the use
of twisted.enterprise would be overkill.
Well, as per the twisted philosophy, using components separately should
always be possible, and so choosing to use twisted.web.resource should
not oblige you to use twisted.enterprise. For a given application,
"enterprise" layer may be more appropriate, or indeed required.
In the example shown, a connection is made and closed per request.
The adbapi integrates a dbpool handling. How would one go about
handling caching of connections and/or loaded data across requests,
and across users (outside of twisted.enterprise)? Would this require
writing a twisted server application? Is there a simpler way to do this?
And, for web resources in general, how does the concept of "web
variables" (variables visible across all requests and user sessions, as
opposed to user session variables) ?
Many thanks, mario
On lundi, jan 27, 2003, at 18:34 Europe/Amsterdam, L. Daniel Burr wrote:
> As promised in the thread about deferreds and resources, here is an
> example of making a database call from a resource, using a thread.
> I've tried to follow the Twisted development guidelines, so please
> let me know if I've used any inappropriate naming conventions, etc.
> I didn't provide epydoc-style docstrings as I had originally hoped;
> I haven't had time to read the epydoc manual yet.
> Next up will be an example using twisted.enterprise, with Row and
> without. Hopefully examples of this sort will help newer users in
> grokking twisted.web, at least until the Woven stuff is ready.
> L. Daniel Burr<dbresource.rpy>
More information about the Twisted-Python