change stop loop function
This commit is contained in:
@@ -9,11 +9,17 @@ from utils.db.db_execution import ExecutionQueryAsync
|
|||||||
|
|
||||||
loop_stop_label: bool = True
|
loop_stop_label: bool = True
|
||||||
|
|
||||||
def internal_loop_stop():
|
async def internal_loop_stop(task: asyncio.Task) -> None:
|
||||||
print("Stopping main Loop")
|
print("Stopping main Loop")
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
global loop_stop_label
|
global loop_stop_label
|
||||||
loop_stop_label = False
|
loop_stop_label = False
|
||||||
|
try:
|
||||||
|
await task
|
||||||
|
print("Cancelled")
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
print("Cancelled exception")
|
||||||
|
pass
|
||||||
|
|
||||||
async def internal_loop(influxdb_client: InfluxDBClientAsync, mysql_client: AsyncSession):
|
async def internal_loop(influxdb_client: InfluxDBClientAsync, mysql_client: AsyncSession):
|
||||||
i = 0
|
i = 0
|
||||||
|
|||||||
8
main.py
8
main.py
@@ -33,13 +33,7 @@ async def startup(fast_api: FastAPI):
|
|||||||
yield
|
yield
|
||||||
finally:
|
finally:
|
||||||
# Shutdown logic
|
# Shutdown logic
|
||||||
internal_loop_stop()
|
await internal_loop_stop(task)
|
||||||
try:
|
|
||||||
await task
|
|
||||||
print("Cancelled")
|
|
||||||
except asyncio.CancelledError:
|
|
||||||
print("Cancelled exception")
|
|
||||||
pass
|
|
||||||
await influxdb_client.close()
|
await influxdb_client.close()
|
||||||
mysql_engine = get_mysql_engine()
|
mysql_engine = get_mysql_engine()
|
||||||
await mysql_client.close()
|
await mysql_client.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user