Skip to content

Commit

Permalink
Make CachedInterpreter the Interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
remram44 committed Oct 2, 2015
1 parent 916dbe8 commit 7d3aed3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
5 changes: 4 additions & 1 deletion vistrails/core/interpreter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
## ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
##
###############################################################################

from __future__ import division

from .cached import CachedInterpreter as Interpreter

from vistrails.core.interpreter.interpreter import ViewUpdatingLogController, \
Interpreter
2 changes: 0 additions & 2 deletions vistrails/core/interpreter/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,3 @@ def set_done_update_hook(self, hook):
"""
self.done_update_hook = hook

##############################################################################
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
from vistrails.core.common import InstanceObject, VistrailsInternalError
from vistrails.core.data_structures.bijectivedict import Bidict
from vistrails.core import debug
from vistrails.core.interpreter.base import AbortExecution, InternalTuple, BaseInterpreter
from vistrails.core.interpreter.base import AbortExecution, BaseInterpreter, \
InternalTuple
from vistrails.core.log.controller import DummyLogController
from vistrails.core.modules.basic_modules import identifier as basic_pkg, \
Generator
Expand Down Expand Up @@ -196,7 +197,7 @@ def add_exec(self, exec_):
Variant_desc = None
InputPort_desc = None

class CachedInterpreter(BaseInterpreter):
class Interpreter(BaseInterpreter):

def __init__(self):
BaseInterpreter.__init__(self)
Expand Down Expand Up @@ -317,7 +318,7 @@ def create_null():
getter = reg.get_descriptor_by_name
descriptor = getter(basic_pkg, 'Null')
return descriptor.module()

def create_constant(param, module):
"""Creates a Constant from a parameter spec"""
getter = reg.get_descriptor_by_name
Expand Down Expand Up @@ -351,7 +352,7 @@ def create_constant(param, module):
self.resolve_variables(vistrail_variables, pipeline)

self.update_params(pipeline, params)

(tmp_to_persistent_module_map,
conn_map,
module_added_set,
Expand All @@ -365,7 +366,7 @@ def create_constant(param, module):
obj.interpreter = self
obj.id = persistent_id
obj.signature = module._signature

# Checking if output should be stored
if module.has_annotation_with_key('annotate_output'):
annotate_output = module.get_annotation_by_key('annotate_output')
Expand Down Expand Up @@ -438,7 +439,7 @@ def create_constant(param, module):
return (tmp_id_to_module_map, tmp_to_persistent_module_map.inverse,
module_added_set, conn_added_set, to_delete, errors)

def execute_pipeline(self, pipeline, tmp_id_to_module_map,
def execute_pipeline(self, pipeline, tmp_id_to_module_map,
persistent_to_tmp_id_map, **kwargs):
def fetch(name, default):
return kwargs.pop(name, default)
Expand Down Expand Up @@ -489,7 +490,7 @@ def make_change_parameter(obj):
obj.in_pipeline = True # set flag to indicate in pipeline
obj.logging = logging_obj
obj.change_parameter = make_change_parameter(obj)

# Update object pipeline information
obj.moduleInfo['locator'] = locator
obj.moduleInfo['version'] = current_version
Expand Down Expand Up @@ -592,7 +593,7 @@ def make_change_parameter(obj):

if self.done_update_hook:
self.done_update_hook(self._persistent_pipeline, self._objects)

# objs, errs, and execs are mappings that use the local ids as keys,
# as opposed to the persistent ids.
# They are thus ideal to external consumption.
Expand Down Expand Up @@ -769,7 +770,7 @@ def annotate_workflow_execution(self, logger, reason, aliases, params):
aliases:dict, params:list)-> None
It will annotate the workflow execution in logger with the reason,
aliases and params.
"""
d = {}
d["__reason__"] = reason
Expand All @@ -778,7 +779,7 @@ def annotate_workflow_execution(self, logger, reason, aliases, params):
if params is not None and isinstance(params, list):
d["__params__"] = pickle.dumps(params)
logger.insert_workflow_exec_annotations(d)

def add_to_persistent_pipeline(self, pipeline):
"""add_to_persistent_pipeline(pipeline):
(module_id_map, connection_id_map, modules_added)
Expand Down Expand Up @@ -836,9 +837,9 @@ def add_to_persistent_pipeline(self, pipeline):
self._persistent_pipeline.compute_signatures()
return (module_id_map, connection_id_map,
modules_added, connections_added)

def find_persistent_entities(self, pipeline):
"""returns a map from a pipeline to the persistent pipeline,
"""returns a map from a pipeline to the persistent pipeline,
assuming those pieces exist"""
persistent_p = self._persistent_pipeline
object_map = {}
Expand Down Expand Up @@ -868,24 +869,24 @@ def find_persistent_entities(self, pipeline):
__instance = None
@staticmethod
def get():
if not CachedInterpreter.__instance:
CachedInterpreter.__instance = CachedInterpreter()
return CachedInterpreter.__instance
if not Interpreter.__instance:
Interpreter.__instance = Interpreter()
return Interpreter.__instance

@staticmethod
def cleanup():
if CachedInterpreter.__instance:
CachedInterpreter.__instance.clear()
if Interpreter.__instance:
Interpreter.__instance.clear()
objs = gc.collect()

@staticmethod
def flush():
if CachedInterpreter.__instance:
CachedInterpreter.__instance.clear()
CachedInterpreter.__instance.create()
if Interpreter.__instance:
Interpreter.__instance.clear()
Interpreter.__instance.create()
objs = gc.collect()

@staticmethod
def clear_package(identifier):
if CachedInterpreter.__instance:
CachedInterpreter.__instance._clear_package(identifier)
if Interpreter.__instance:
Interpreter.__instance._clear_package(identifier)
4 changes: 2 additions & 2 deletions vistrails/gui/application_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
from vistrails.core.vistrail.vistrail import Vistrail
from vistrails.core import system
from vistrails.core.modules.module_registry import get_module_registry as module_registry
from vistrails.core import interpreter
from vistrails.core.interpreter import Interpreter
from vistrails.core.packagemanager import get_package_manager
from vistrails.core.thumbnails import ThumbnailCache
import vistrails.db.services.io
Expand Down Expand Up @@ -793,7 +793,7 @@ def executeMedley(self, xml_medley, extra_info=None):
update_vistrail=False,
extra_info=extra_info)
self.server_logger.info("Memory usage: %s"% self.memory_usage())
interpreter.cached.CachedInterpreter.flush()
Interpreter.flush()
except Exception, e:
self.server_logger.error(str(e))
return (str(e), 0)
Expand Down

0 comments on commit 7d3aed3

Please sign in to comment.