Replace coro logic with tortoise.run_async
This commit is contained in:
		| @@ -8,7 +8,7 @@ from typing import List | |||||||
|  |  | ||||||
| import click | import click | ||||||
| from click import Context, UsageError | from click import Context, UsageError | ||||||
| from tortoise import Tortoise, generate_schema_for_client | from tortoise import Tortoise, generate_schema_for_client, run_async | ||||||
| from tortoise.exceptions import OperationalError | from tortoise.exceptions import OperationalError | ||||||
| from tortoise.transactions import in_transaction | from tortoise.transactions import in_transaction | ||||||
| from tortoise.utils import get_schema_sql | from tortoise.utils import get_schema_sql | ||||||
| @@ -34,11 +34,7 @@ parser = ConfigParser() | |||||||
| def coro(f): | def coro(f): | ||||||
|     @wraps(f) |     @wraps(f) | ||||||
|     def wrapper(*args, **kwargs): |     def wrapper(*args, **kwargs): | ||||||
|         loop = asyncio.get_event_loop() |         run_async(f(*args, **kwargs)) | ||||||
|         try: |  | ||||||
|             loop.run_until_complete(f(*args, **kwargs)) |  | ||||||
|         finally: |  | ||||||
|             loop.run_until_complete(Tortoise.close_connections()) |  | ||||||
|  |  | ||||||
|     return wrapper |     return wrapper | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user