Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible memory leak #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/gafferpy/gaffer_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,50 @@
# limitations under the License.
#

"""
This module contains Python copies of Gaffer config java classes
"""
This module contains Python copies of Gaffer config java classes
"""

import inspect
import sys

from gafferpy.gaffer_core import JsonConverter


class GetGraph:
def __init__(self, _url=""):
self._url = _url

def get_url(self):
return self._url


# Import generated config implementations from fishbowl
from gafferpy.generated_api.config import *

# Add an alternative name for GetFilterFunctions


class GetClassFilterFunctions(GetFilterFunctions):
def __init__(self, class_name=""):
super().__init__(class_name)


class IsOperationSupported:
def __init__(self, operation=None):
self.operation = operation

def get_operation(self):
return self.operation

def cleanup_config_json_map():
"""Clear existing mappings to avoid memory bloat."""
JsonConverter.GENERIC_JSON_CONVERTERS.clear()
JsonConverter.CLASS_MAP.clear()

def load_config_json_map():
for name, class_obj in inspect.getmembers(
sys.modules[__name__], inspect.isclass):
"""Load configuration class mappings and clear previous ones."""
# Clear existing mappings to avoid memory bloat
cleanup_config_json_map()

for name, class_obj in inspect.getmembers(sys.modules[__name__], inspect.isclass):
if hasattr(class_obj, "CLASS"):
JsonConverter.GENERIC_JSON_CONVERTERS[class_obj.CLASS] = \
lambda obj, class_obj=class_obj: class_obj(**obj)
JsonConverter.CLASS_MAP[class_obj.CLASS] = class_obj


load_config_json_map()
Loading