I think your options are:

   - Make the object pickleable 
   
<https://docs.python.org/2/library/pickle.html#pickling-and-unpickling-extension-types>
 
   and store it in the session (this is only necessary if you really need a 
   separate object for each user's session).
   - Store the object in cache.ram (you can use a key for each user if you 
   need multiple objects, but remember to clear old keys periodically or RAM 
   will fill up).
   - Create a singleton or, if necessary, a "multiton" (keyed registry of 
   singletons -- e.g., http://stackoverflow.com/a/7493603/440323).

Anthony

On Sunday, November 30, 2014 7:00:48 AM UTC-5, aapaap wrote:
>
> hello, 
>
> I've a class, that reads a huge file and parses it. 
> Therefor I want just one instance per session or even one over all 
> sessions. 
>
> # The next code (placed in controler default.py) generates an error 
>
> if session.Book_Loaded is None : 
>    session.Book_Loaded = PuntHoofd_support.PuntHoofd_Doc ( Text ) 
>    session.Test_One_Instance = random.randint ( 0, 1000 ) 
> Book_Source = session.Book_Loaded 
> Test_One_Instance = session.Test_One_Instance 
>
> #Chapters = Test_One_Instance.Get_Chapters ( Book ) 
> #AttributeError: 'str' object has no attribute 'Get_Chapters' 
>
> Error: session.Book_Loaded has become a string ???? 
>
>
> Now I've found a workaround that does work: 
> try : 
>    sys.Book_Loaded 
> except : 
>    sys.Book_Loaded = PuntHoofd_support.PuntHoofd_Doc ( Text ) 
>    sys.Test_One_Instance = random.randint ( 0, 1000 ) 
> Book_Source = sys.Book_Loaded 
> Test_One_Instance = sys.Test_One_Instance 
>
> Is there a better/cleaner way to realize this ? 
>
> thanks, 
> Stef 
>
>

-- 
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.
For more options, visit https://groups.google.com/d/optout.

Reply via email to