import imp
import json
import sys


def run(task, inputs, outputs, task_inputs, task_outputs, **kwargs):
    custom = imp.new_module("custom")

    for name in inputs:
        custom.__dict__[name] = inputs[name]["script_data"]

    custom.__dict__['_job_manager'] = kwargs.get('_job_manager')

    try:
        exec task["script"] in custom.__dict__
    except Exception, e:
        trace = sys.exc_info()[2]
        lines = task["script"].split("\n")
        lines = [(str(i+1) + ": " + lines[i]) for i in xrange(len(lines))]
        error = (
            str(e) + "\nScript:\n" + "\n".join(lines) +
            "\nTask:\n" + json.dumps(task, indent=4)
        )
        raise Exception(error), None, trace

    for name, task_output in task_outputs.iteritems():
        outputs[name]["script_data"] = custom.__dict__[name]

@@ -137,16 +137,82 @@
 stom%22)%0A%0A
+    custom.__dict__%5B'_job_manager'%5D = kwargs.get('_job_manager')%0A%0A
     for 
@@ -292,74 +292,8 @@
 %22%5D%0A%0A
-    custom.__dict__%5B'_job_manager'%5D = kwargs.get('_job_manager')%0A%0A
     

Allow _job_manager special object to be overriden by task if desired