How to use the skypy.ResumeState function in skypy

To help you get started, we’ve selected a few skypy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mrry / ciel / src / python / skywriting / runtime / worker / skypy / stub.py View on Github external
runtime_response = skypy.fetch_ref(entry_dict["coro_ref"], "open_ref", message_helper)
            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"],
                                                     py_ref=entry_dict["py_ref"])
            user_coro = stackless.coroutine()
            user_coro.bind(skypy.start_script, user_script_namespace.__dict__[entry_dict["entry_point"]], entry_dict["entry_args"])
            resume_state = skypy.ResumeState(persistent_state, user_coro)

        skypy.current_task = skypy.SkyPyTask(main_coro, 
                                             resume_state.persistent_state,
                                             message_helper,
                                             file_outputs)

        user_coro.switch()
        # We're back -- either the user script is done, or else it's stuck waiting on a reference.
        if skypy.current_task.halt_reason == skypy.HALT_RUNTIME_EXCEPTION:
            report = "User script exception %s\n%s" % (str(skypy.current_task.script_return_val), skypy.current_task.script_backtrace)
            out_message = ("error", {"report": report})
        else:
            if skypy.current_task.halt_reason == skypy.HALT_REFERENCE_UNAVAILABLE:
                coro_ref = skypy.save_state(resume_state)
                out_message = ("tail_spawn", 
                                {"executor_name": "skypy",