Last active
October 28, 2020 19:31
-
-
Save beattyml1/94eb76bce8d7cec77570e96344888031 to your computer and use it in GitHub Desktop.
Converting static sql alchemy global session db session to thread safe/per thread session
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Module: | |
@property | |
def session(self): | |
local = threading.local() | |
_session = getattr(local, 'session', None) | |
if _session is None: | |
local.session = build_session() | |
return _session | |
sys.modules[__name__] = Module() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment