11# noinspection PyPackageRequirements
22from sanic .exceptions import NotFound
33from sqlalchemy .engine .url import URL
4- try :
5- # noinspection PyPackageRequirements
6- from aiocontextvars import enable_inherit , disable_inherit
7- except ImportError :
8- enable_inherit = disable_inherit = lambda loop : None
94
105from ..api import Gino as _Gino , GinoExecutor as _Executor
116from ..engine import GinoConnection as _Connection , GinoEngine as _Engine
@@ -86,8 +81,6 @@ def __init__(self, app=None, *args, **kwargs):
8681 self .init_app (app )
8782
8883 def init_app (self , app ):
89- inherit_enabled = [False ]
90-
9184 if app .config .setdefault ('DB_USE_CONNECTION_FOR_REQUEST' , True ):
9285 @app .middleware ('request' )
9386 async def on_request (request ):
@@ -101,10 +94,6 @@ async def on_response(request, _):
10194
10295 @app .listener ('before_server_start' )
10396 async def before_server_start (_ , loop ):
104- if app .config .setdefault ('DB_USE_CONNECTION_FOR_REQUEST' , True ):
105- enable_inherit (loop )
106- inherit_enabled [0 ] = True
107-
10897 if app .config .get ('DB_DSN' ):
10998 dsn = app .config .DB_DSN
11099 else :
@@ -128,9 +117,6 @@ async def before_server_start(_, loop):
128117 @app .listener ('after_server_stop' )
129118 async def after_server_stop (_ , loop ):
130119 await self .pop_bind ().close ()
131- if inherit_enabled [0 ]:
132- disable_inherit (loop )
133- inherit_enabled [0 ] = False
134120
135121 async def first_or_404 (self , * args , ** kwargs ):
136122 rv = await self .first (* args , ** kwargs )
0 commit comments