4 ms·
I am very confused how redis could get involved here. I hereby declare this open source :) import threading _local = threading.local() class Sessi
by chronial 9y ago
I am very confused how redis could get involved here. I hereby declare this open source :)
import threading
_local = threading.local()
class SessionKeeperMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
_local.session = request.session
response = self.process_request(request)
_local.session = None
return response
def my_callback():
do stuff with _local.session
- Demiurge 9y agoWell, the idea is that I would have to store a variable and access it without races, so I would use an external storage library. This is pretty cool though, I've never used python threading for state, thanks a lot!
- filmor 9y agoThis doesn't use threading, just a thread-local variable (i.e. a variable that points to different memory locations for each thread) to make the whole thing threadsafe.