mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 04:10:33 +08:00
ff8018db75
* draft of local scheduler * API * update APIs * fix * update * Rename halo -> photon. * Add build directory. * Update common submodule. * More renaming. * Fix python ctypes. * Compile in travis. * Process generic messages and not just tasks. * Move free outside of switch. * Formatting and address comments. * Remove event loop from local scheduler state. * Use accept_client from common. * Use bind_ipc_sock from common. * Fix tests. * Update common submodule. * Fix formatting.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import ctypes
|
|
import os
|
|
|
|
photon_client_library_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "../../build/photon_client.so")
|
|
photon_client_library = ctypes.cdll.LoadLibrary(photon_client_library_path)
|
|
photon_client_library.alloc_task_spec.restype = ctypes.c_void_p
|
|
photon_client_library.photon_connect.restype = ctypes.c_void_p
|
|
photon_client_library.photon_submit.restype = None
|
|
|
|
ID = ctypes.c_ubyte * 20
|
|
|
|
class UniqueID(ctypes.Structure):
|
|
_fields_ = [("unique_id", ID)]
|
|
|
|
def make_id(string):
|
|
if len(string) != 20:
|
|
raise Exception("PlasmaIDs must be 20 characters long")
|
|
unique_id = map(ord, string)
|
|
return UniqueID(unique_id=ID(*unique_id))
|
|
|
|
class Task(object):
|
|
def __init__(self, function_id, args):
|
|
function_id = make_id(function_id)
|
|
self.task_spec = ctypes.c_void_p(photon_client_library.alloc_task_spec(function_id, len(args), 1, 0))
|
|
for arg in args:
|
|
photon_client_library.task_args_add_ref(self.task_spec, arg)
|
|
|
|
def __del__(self):
|
|
photon_client_library.free_task_spec(self.task_spec)
|
|
|
|
class PhotonClient(object):
|
|
|
|
def __init__(self, socket_name):
|
|
self.photon_conn = ctypes.c_void_p(photon_client_library.photon_connect(socket_name))
|
|
|
|
def submit(self, function_id, args):
|
|
task = Task(function_id, args)
|
|
photon_client_library.photon_submit(self.photon_conn, task.task_spec)
|