def counter(ref): cached_result = soft_cache.try_get_cache([ref], "wc") if cached_result is not None: print "Counter: got cached result! It was", cached_result else: with skypy.deref_as_raw_file(ref, make_sweetheart=True) as in_fp: cached_result = len(in_fp.read()) print "Counter: calculated result anew. It was", cached_result soft_cache.put_cache([ref], "wc", cached_result) return cached_result
if skypy.current_task is None: # Otherwise we're in fixed mode -- this new task continues the old one user_script_namespace = user_script_namespaces.get(entry_dict["py_ref"].id, None) if user_script_namespace is None: runtime_response = skypy.fetch_ref(entry_dict["py_ref"], "open_ref", message_helper, make_sweetheart=True) source_filename = runtime_response["filename"] user_script_namespace = imp.load_source(str("user_namespace_%s" % entry_dict["py_ref"].id), source_filename) user_script_namespaces[entry_dict["py_ref"].id] = user_script_namespace else: print >>sys.stderr, "SkyPy: Using pre-parsed .py file" if "coro_ref" in entry_dict: print >>sys.stderr, "SkyPy: Resuming" resume_state = soft_cache.try_get_cache([entry_dict["coro_ref"]], "coro") if resume_state is not None: print >>sys.stderr, "SkyPy: Resuming from soft-cached coroutine" else: runtime_response = skypy.fetch_ref(entry_dict["coro_ref"], "open_ref", message_helper, make_sweetheart=True) if "strdata" in runtime_response: fp = StringIO(decode_datavalue_string(runtime_response["strdata"])) else: fp = open(runtime_response["filename"], "r") with fp: resume_state = pickle.load(fp) user_coro = resume_state.coro else: print >>sys.stderr, "Entering at", entry_dict["entry_point"], "args", entry_dict["entry_args"] persistent_state = skypy.PersistentState(export_json=entry_dict["export_json"], extra_outputs=entry_dict["extra_outputs"],