Fixed memory() and RET usage
This commit is contained in:
@@ -64,6 +64,7 @@ class Sheerka(Concept):
|
||||
USER_CONCEPTS_KEYS = "User_Concepts" # sequential key for user defined concepts
|
||||
|
||||
MAX_EXECUTION_HISTORY = 100
|
||||
MAX_RETURN_VALUES_HISTORY = 100
|
||||
|
||||
def __init__(self, cache_only=False, debug=False, loggers=None):
|
||||
self.init_logging(debug, loggers)
|
||||
@@ -113,6 +114,7 @@ class Sheerka(Concept):
|
||||
self.locals = {}
|
||||
|
||||
self.last_executions = []
|
||||
self.last_return_values = []
|
||||
|
||||
@property
|
||||
def resolved_concepts_by_first_keyword(self):
|
||||
@@ -138,21 +140,23 @@ class Sheerka(Concept):
|
||||
def chicken_and_eggs(self):
|
||||
return self.cache_manager.caches[self.CHICKEN_AND_EGG_CONCEPTS_ENTRY].cache
|
||||
|
||||
def bind_service_method(self, bound_method, has_side_effect, as_name=None):
|
||||
def bind_service_method(self, bound_method, has_side_effect, as_name=None, visible=True):
|
||||
"""
|
||||
Bind service method to sheerka instance for ease of use ?
|
||||
:param bound_method:
|
||||
:param has_side_effect: False if the method is safe
|
||||
:param as_name:
|
||||
:param as_name: give another name to the method
|
||||
:param visible: make the method visible to Sheerka
|
||||
:return:
|
||||
"""
|
||||
if as_name is None:
|
||||
as_name = bound_method.__name__
|
||||
|
||||
signature = inspect.signature(bound_method)
|
||||
if len(signature.parameters) > 0 and list(signature.parameters.keys())[0] == "context":
|
||||
self.methods_with_context.add(as_name)
|
||||
self.sheerka_methods[as_name] = SheerkaMethod(bound_method, has_side_effect)
|
||||
if visible:
|
||||
signature = inspect.signature(bound_method)
|
||||
if len(signature.parameters) > 0 and list(signature.parameters.keys())[0] == "context":
|
||||
self.methods_with_context.add(as_name)
|
||||
self.sheerka_methods[as_name] = SheerkaMethod(bound_method, has_side_effect)
|
||||
|
||||
setattr(self, as_name, bound_method)
|
||||
|
||||
@@ -437,6 +441,10 @@ class Sheerka(Concept):
|
||||
del self.last_executions[0]
|
||||
self.last_executions.append(execution_context)
|
||||
|
||||
if len(self.last_return_values) == self.MAX_RETURN_VALUES_HISTORY:
|
||||
del self.last_return_values[0]
|
||||
self.last_return_values.append(ret)
|
||||
|
||||
return ret
|
||||
|
||||
def print(self, result, instructions=None):
|
||||
|
||||
Reference in New Issue
Block a user