Use the Django cache for sandboxed code execution.

This commit is contained in:
Ned Batchelder
2013-04-01 16:33:59 -04:00
parent c8b908a244
commit 5e7d328e7f
4 changed files with 14 additions and 5 deletions

View File

@@ -462,7 +462,13 @@ class LoncapaProblem(object):
if all_code:
try:
safe_exec.safe_exec(all_code, context, random_seed=self.seed, python_path=python_path)
safe_exec.safe_exec(
all_code,
context,
random_seed=self.seed,
python_path=python_path,
cache=self.system.cache,
)
except Exception as err:
log.exception("Error while execing script code: " + all_code)
msg = "Error while executing script code: %s" % str(err).replace('<', '&lt;')

View File

@@ -938,7 +938,7 @@ class CustomResponse(LoncapaResponse):
'ans': ans,
}
globals_dict.update(kwargs)
safe_exec.safe_exec(code, globals_dict)
safe_exec.safe_exec(code, globals_dict, cache=self.system.cache)
return globals_dict['cfn_return']
return check_function
@@ -1055,7 +1055,7 @@ class CustomResponse(LoncapaResponse):
# exec the check function
if isinstance(self.code, basestring):
try:
safe_exec.safe_exec(self.code, self.context)
safe_exec.safe_exec(self.code, self.context, cache=self.system.cache)
except Exception as err:
self._handle_exec_exception(err)
@@ -1783,7 +1783,7 @@ class SchematicResponse(LoncapaResponse):
json.loads(student_answers[k]) for k in sorted(self.answer_ids)
]
self.context.update({'submission': submission})
safe_exec.safe_exec(self.code, self.context)
safe_exec.safe_exec(self.code, self.context, cache=self.system.cache)
cmap = CorrectMap()
cmap.set_dict(dict(zip(sorted(self.answer_ids), self.context['correct'])))
return cmap

View File

@@ -33,5 +33,6 @@ test_system = Mock(
debug=True,
xqueue={'interface': xqueue_interface, 'construct_callback': calledback_url, 'default_queuename': 'testqueue', 'waittime': 10},
node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules"),
anonymous_student_id='student'
anonymous_student_id='student',
cache=None,
)