spyce
         
home     documentation     download     Spyce logo


Documentation - Modules

Prev: 3.8.6 - Session Up: 3.8 - Modules Next: 3.8.8 - Transform

3.8.7. Pool

The pool module provides support for server-pooled variables. That is support for variables whose lifetime begins when declared, and ends when explicitly deleted or when the server dies. These variables are often useful for caching information that would be expensive to compute from scratch for each request. Another common use of pool variables is to store file- or memory-based lock objects for concurrency control. A pooled variable can hold any Python value.

The pool module may be accessed as a regular dictionary, supporting the usual get, set, delete, has_key, keys, values and clear operations.

The example below shows how the module is used:

examples/pool.spy
[[.import names="pool"]]
<html><body>
  The pool module supports long-lived server-pooled objects,<br>
  useful for database connections, and other variables<br>
  that are expensive to compute.<br>
  [[\
    if 'foo' in pool:
      print 'Pooled object foo EXISTS.'
    else:
      pool['foo'] = 1
      print 'Pooled object foo CREATED.'
  ]]
  <br>
  Value: [[=pool['foo'] ]] <p>
</body></html>
Run this code

Pool performance suffers when not used with the Spyce webserver in threaded concurrency mode; Spyce has to un/pickle the shared pool with each request since there is no single long-lived process that can keep the data in-memory.


Prev: 3.8.6 - Session Up: 3.8 - Modules Next: 3.8.8 - Transform


Spyce logo
Python Server Pages
version 2.1.3
Spyce Powered SourceForge Logo