def as_future(self, object_id, check_ready=True): """Turn an object_id into a Future object. Args: object_id: A Ray's object_id. check_ready (bool): If true, check if the object_id is ready. Returns: PlasmaObjectFuture: A future object that waits the object_id. """ if not isinstance(object_id, ray.ObjectID): raise TypeError("Input should be an ObjectID.") plain_object_id = plasma.ObjectID(object_id.id()) fut = PlasmaObjectFuture(loop=self._loop, object_id=plain_object_id) if check_ready: ready, _ = ray.wait([object_id], timeout=0) if ready: if self._loop.get_debug(): logger.debug("%s has been ready.", plain_object_id) self._complete_future(fut) return fut if plain_object_id not in self._waiting_dict: linked_list = PlasmaObjectLinkedList(self._loop, plain_object_id) linked_list.add_done_callback(self._unregister_callback) self._waiting_dict[plain_object_id] = linked_list self._waiting_dict[plain_object_id].append(fut) if self._loop.get_debug(): logger.debug("%s added to the waiting list.", fut) return fut
def remove(self, future): """Remove an object from the linked list. Args: future (PlasmaObjectFuture): A PlasmaObjectFuture instance. """ if self._loop.get_debug(): logger.debug("Removing %s from the linked list.", future) if future.prev is None: assert future is self.head self.head = future.next if self.head is None: self.tail = None if not self.cancelled(): self.set_result(None) else: self.head.prev = None elif future.next is None: assert future is self.tail self.tail = future.prev if self.tail is None: self.head = None if not self.cancelled(): self.set_result(None) else: self.tail.prev = None
def remove(self, future): """Remove an object from the linked list. Args: future (PlasmaObjectFuture): A PlasmaObjectFuture instance. """ if self._loop.get_debug(): logger.debug("Removing %s from the linked list.", future) if future.prev is None: assert future is self.head self.head = future.next if self.head is None: self.tail = None if not self.cancelled(): self.set_result(None) else: self.head.prev = None elif future.next is None: assert future is self.tail self.tail = future.prev if self.tail is None: self.head = None if not self.cancelled(): self.set_result(None) else: self.tail.prev = None
def as_future(self, object_id, check_ready=True): """Turn an object_id into a Future object. Args: object_id: A Ray's object_id. check_ready (bool): If true, check if the object_id is ready. Returns: PlasmaObjectFuture: A future object that waits the object_id. """ if not isinstance(object_id, ray.ObjectID): raise TypeError("Input should be an ObjectID.") plain_object_id = plasma.ObjectID(object_id.binary()) fut = PlasmaObjectFuture(loop=self._loop, object_id=plain_object_id) if check_ready: ready, _ = ray.wait([object_id], timeout=0) if ready: if self._loop.get_debug(): logger.debug("%s has been ready.", plain_object_id) self._complete_future(fut) return fut if plain_object_id not in self._waiting_dict: linked_list = PlasmaObjectLinkedList(self._loop, plain_object_id) linked_list.add_done_callback(self._unregister_callback) self._waiting_dict[plain_object_id] = linked_list self._waiting_dict[plain_object_id].append(fut) if self._loop.get_debug(): logger.debug("%s added to the waiting list.", fut) return fut
async def _async_init(): global handler if handler is None: worker = ray.worker.global_worker loop = asyncio.get_event_loop() handler = PlasmaEventHandler(loop, worker) worker.core_worker.set_plasma_added_callback(handler) logger.debug("AsyncPlasma Connection Created!")
def complete_closure(): try: fut.set_result(obj) except asyncio.InvalidStateError: # Avoid issues where process_notifications # and check_ready both get executed logger.debug("Failed to set result for future {}." "Most likely already set.".format(fut))
async def _async_init(): global handler, transport, protocol if handler is None: worker = ray.worker.global_worker loop = asyncio.get_event_loop() worker.plasma_client.subscribe() rsock = worker.plasma_client.get_notification_socket() handler = PlasmaEventHandler(loop, worker) transport, protocol = await loop.create_connection( lambda: PlasmaProtocol(worker.plasma_client, handler), sock=rsock) logger.debug("AsyncPlasma Connection Created!")
async def _async_init(): global handler, transport, protocol if handler is None: worker = ray.worker.global_worker plasma_client = thread_safe_client( plasma.connect(worker.node.plasma_store_socket_name, None, 0, 300)) loop = asyncio.get_event_loop() plasma_client.subscribe() rsock = plasma_client.get_notification_socket() handler = PlasmaEventHandler(loop, worker) transport, protocol = await loop.create_connection( lambda: PlasmaProtocol(plasma_client, handler), sock=rsock) logger.debug("AsyncPlasma Connection Created!")
def _complete_future(event_handler, ray_object_id): # TODO(ilr): Consider race condition between popping from the # waiting_dict and as_future appending to the waiting_dict's list. logger.debug( "Completing plasma futures for object id {}".format(ray_object_id)) obj = event_handler._worker.get_objects([ray_object_id], timeout=0)[0] futures = event_handler._waiting_dict.pop(ray_object_id) for fut in futures: try: fut.set_result(obj) except asyncio.InvalidStateError: # Avoid issues where process_notifications # and check_immediately both get executed logger.debug("Failed to set result for future {}." "Most likely already set.".format(fut))
def _complete_future(self, ray_object_id): # TODO(ilr): Consider race condition between popping from the # waiting_dict and as_future appending to the waiting_dict's list. logger.debug( "Completing plasma futures for object id {}".format(ray_object_id)) obj = self._worker.get_objects([ray_object_id])[0] futures = self._waiting_dict.pop(ray_object_id) for fut in futures: loop = fut._loop def complete_closure(): try: fut.set_result(obj) except asyncio.InvalidStateError: # Avoid issues where process_notifications # and check_ready both get executed logger.debug("Failed to set result for future {}." "Most likely already set.".format(fut)) loop.call_soon_threadsafe(complete_closure)
def eof_received(self): logger.debug("PlasmaProtocol - EOF received.") self.transport.close()
def connection_lost(self, exc): # The socket has been closed logger.debug("PlasmaProtocol - connection lost.")
def eof_received(self): logger.debug("PlasmaProtocol - EOF received.") self.transport.close()
def connection_lost(self, exc): # The socket has been closed logger.debug("PlasmaProtocol - connection lost.")