Don't close db connections when group function \(cli\) is run
This commit is contained in:
parent
14d20455e6
commit
e74fc304a5
@ -8,7 +8,7 @@ from typing import List
|
||||
|
||||
import click
|
||||
from click import Context, UsageError
|
||||
from tortoise import Tortoise, generate_schema_for_client, run_async
|
||||
from tortoise import Tortoise, generate_schema_for_client
|
||||
from tortoise.exceptions import OperationalError
|
||||
from tortoise.transactions import in_transaction
|
||||
from tortoise.utils import get_schema_sql
|
||||
@ -34,7 +34,14 @@ parser = ConfigParser()
|
||||
def coro(f):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
run_async(f(*args, **kwargs))
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
# Close db connections at the end of all all but the cli group function
|
||||
try:
|
||||
loop.run_until_complete(f(*args, **kwargs))
|
||||
finally:
|
||||
if f.__name__ != "cli":
|
||||
loop.run_until_complete(Tortoise.close_connections())
|
||||
|
||||
return wrapper
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user