[web2py] Re: Keeping objects between requests

2020-04-07 Thread Val K
Yes, see pydal implementation 
https://github.com/web2py/pydal/blob/master/pydal/connection.py
It is just 176 lines

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c697169f-3828-4953-82e5-d659d88fe89a%40googlegroups.com.


[web2py] Re: Keeping objects between requests

2020-04-07 Thread Joel Samuelsson
Thanks, this works. Is that how people usually do to keep db connections 
alive?

Den tisdag 7 april 2020 kl. 12:30:54 UTC+2 skrev Val K:
>
> Ups, sorry current is thread local and renew per request, use regular 
> mudule

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/1110746d-e543-49e9-95ca-c23c0feb788b%40googlegroups.com.


[web2py] Re: Keeping objects between requests

2020-04-07 Thread Val K
Ups, sorry current is thread local and renew per request, use regular mudule

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/9763144a-bf46-4d1d-887a-c1e909530004%40googlegroups.com.


[web2py] Re: Keeping objects between requests

2020-04-07 Thread Joel Samuelsson
Did this in the top of a controller:
from gluon import current
try:
 if current.ts_db is not None:
   Databases.setTSDB(current.ts_db)
except AttributeError:
 current.ts_db = Databases.setTSDB()

Databases is a model and setTSDB looks liks this:
 @staticmethod
 def setTSDB(db = None):
   if db is None:
 logger.debug("Creating new TS DB")
 db = CassandraConnection([TS_DB_URL], TS_DB_PORT)
   DriverFactory.setDB(db)
 return db

Whenever I make a request I get the "Creating new TS DB" log so the object 
doesn't seem to be saved. Any ideas why?
I should mention that I'm running web2py behind Apache with mod_wsgi.

Den måndag 6 april 2020 kl. 11:51:12 UTC+2 skrev Val K:
>
> You can save any object in the module or current, but if you use more than 
> one worker you will have independent instance of that object per worker

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/b1881422-5a42-4fb3-9efd-7b8de6ae5bf2%40googlegroups.com.