up vote down votefavorite <http://stackoverflow.com/questions/35605876/web2py-unpickle-session-data-from-mysql#>
In order for a progress bar using cache.ram, and an ajax call to work properly, there is a need to clean (or just unlock?) sessions. If the app doesn't use session variables to pass to other controllers then *session.forget(response)* is sufficient to unlock the sessions and let the Ajax do multiple calls. (Without the *session.forget(response)* - the progress bar will run only the first time, requiring clearing the sessions manually each time). If on the other hand, the app needs session variables (as my app does indeed) - then session.forget doesn't do much good since it brakes the session variables chain of transmission to other controllers. As per Anthony suggestion in another post (Progress bar and sessions): I tried first storing sessions in cookies (with maximum zlib compression - level 9) . Still it's not enough for my needs ... I need more than 10k per session to be passed to other controllers, and as mentioned in the book - keeping sessions in cookies is not a good solution if the session are expected to be large (more than 4k/cookie, I assume). So I am trying session.connect with a MySQL db. I can see the table web2py_session_AppName being populated and I understand the session_data column is pickled with cPickle. How do I unpickle the information in session_data column from a MySQL table ? I tried using cPickle.loads...with the data as is, with the data as a string...but it still throws a "bad pickle error" Here is the controller: def index(): `session.Yawza = 'Yawza from index'` `cache.ram(CacheKeyUID, lambda: 0, 0)` `return dict()` As a simulation of the lengthy process I need the progress bar for: def cache_in_ram(): `for i in range(int(1e5)):` `avoda = int((i/(1e5))*100)` `cache.ram(CacheKeyUID, lambda:avoda, 0)` `session.Yawza = " Yawza from the cache_in_ram"` `redirect(URL('Test'))` And this is the function used by the Ajax calls to provide values for the progress bar: def cache_reader(): `return cache.ram(CacheKeyUID, lambda: None, None)` def Test(): `return dict(message = 'Long process ended')` The above will have the progress bar work ONLY the first time. After that progress bar will not work (due to locking by the multiple ajax calls) - unless I manually clear sessions or programmatically do a *session.forget(response)* which will unfortunately eliminate the session.Yawza. I need this session.Yawza for OTHER purposes than the progress bar, in other controllers downstream. Adding *session.connect(request,response,cookie_key='yoursecret',compression_level=9)* to my db.py helps, but is limited to 4k size cookies. I need bigger cookies than that. Thus, I moved towards storing sessions in the db, which in my case is a MySQL db. Defined *session.connect(request, response, db)* in db.py. I can see in MySQL the table *web2py_session_AppName* being populated, but I do NOT have access to session.Yawza at all. Not the one coming from the index function and not from the cache_in_ram function. That's the reason I thought I should MANUALLY unpickle the session_data column...to get access to session.Yawza which must be hiding there. Here is a small sample of what can be found in the session_data column in the MySQL table for web2py_sessions_MyAppName : gAJjZ2x1b24uZ2xvYmFscwpTZXNzaW9uCnEBfXECVQVZYXd6YXEDVQ1mcm9tIHRleHQgYm9...etc...etc.. It doesn't look like a kosher pickle to me ... ;-)) What am I doing or not doing correctly in order to benefit from the multiple ajax calls, no sessions locking and still use session variables to transfer info to other controllers ? Thanks -- 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.