title: Standalone web2py-DAL with Pyramid - requests, threads and memory
body: <p>I'm building an app on Pyramid framework and would like to use the web2py-DAL with it. Firebird-embedded is the database of choice.</p>
  
  <p>That works great until I try to call multiple views from one web page asynchronously. Different errors like "Invalid cursor state", "Invalid cursor reference" or "Attempt to reclose a closed cursor" are coming up from the kinterbasdb driver where sqlite just breaks down without any error messages and takes python with it. These view callables are doing nothing but simple reads by SELECTing.</p>
  
  <p>This happens in the case that pyramids root factory returns the same DAL object with each request. It seems like threads form different requests are working with the same cursor object, so the cursor gets closed while the other thread assumes the cursor to be here.</p>
  
  <p>If I create a new DAL object on each request I get an other problem - every new connection on each request allocates memory and this memory doesn't get free. So after some docents requests there are some hundred MB wasted memory.</p>
  
  <p>Unfortunately Sqlalchemy is not an option for this project.</p>
  
  <p>Are there any ideas?</p>