Skip to content

Commit

Permalink
tcl_asyncdelete async handler fix
Browse files Browse the repository at this point in the history
Resolved an infrequent bug that occurred when there was a high volume of requests for the Matplotlib plot. The issue was related to a RuntimeError where the tcl_asyncdelete async handler was being deleted by an incorrect thread. Please refer to the following Stack Overflow thread for more information: https://stackoverflow.com/a/29172195.
  • Loading branch information
konmaz committed May 3, 2023
1 parent ef299ec commit ca02c8d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/CleanEmonBackend/API/API.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
"""This module defines the core functionality of the API"""

import os

from datetime import datetime
from datetime import timedelta
from io import BytesIO

from typing import List
from typing import Any
from typing import Dict
from typing import List, Optional
from typing import Union
from typing import Any

from CleanEmonCore.models import EnergyData

from .. import RES_DIR
from CleanEmonBackend.lib.DBConnector import fetch_data
from ..lib.DBConnector import adapter
from ..lib.DBConnector import send_meta
from ..lib.DBConnector import get_view_daily_consumption
from ..lib.DBConnector import get_last_value
from ..lib.DBConnector import get_view_daily_consumption
from ..lib.DBConnector import send_meta
from ..lib.plots import plot_data


def get_data(date: str, from_cache: bool, sensors: List[str] = None, db: str = None, keep_last_only : bool = False) -> EnergyData:
def get_data(date: Optional[str], from_cache: bool, sensors: List[str] = None, db: str = None, keep_last_only : bool = False) -> EnergyData:
"""Fetches and prepares the daily data that will be returned, filtering in the provided `sensors`.
Note that there is no need to explicitly specify the "timestamp sensor", as it will always be included.
Expand Down
2 changes: 1 addition & 1 deletion src/CleanEmonBackend/API/app_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def get_json_date_mean_consumption(dev_id: str = None, date: str = None, from_ca
raise MissingMetadataField('Household m2')
return res

@app.get("/dev_id/{dev_id}/meta/", tags=["Metadata"])
@app.get("/dev_id/{dev_id}/meta", tags=["Metadata"])
@app.get("/dev_id/{dev_id}/meta/{field}", tags=["Metadata"])
def get_json_meta(dev_id: str = None, field: str = None):
"""Returns the metadata for the current house.
Expand Down
2 changes: 2 additions & 0 deletions src/CleanEmonBackend/lib/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from io import BytesIO

from typing import List
import matplotlib

matplotlib.use('svg')
from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
Expand Down

0 comments on commit ca02c8d

Please sign in to comment.