diff --git a/python/ray/worker.py b/python/ray/worker.py index 61b66c005..d409662a1 100644 --- a/python/ray/worker.py +++ b/python/ray/worker.py @@ -289,16 +289,21 @@ class Worker: serialized_value, object_ref=object_ref)) def raise_errors(self, data_metadata_pairs, object_refs): - context = self.get_serialization_context() - out = context.deserialize_objects(data_metadata_pairs, object_refs) + out = self.deserialize_objects(data_metadata_pairs, object_refs) if "RAY_IGNORE_UNHANDLED_ERRORS" in os.environ: return for e in out: _unhandled_error_handler(e) def deserialize_objects(self, data_metadata_pairs, object_refs): - context = self.get_serialization_context() - return context.deserialize_objects(data_metadata_pairs, object_refs) + # Function actor manager or the import thread may call pickle.loads + # at the same time which can lead to failed imports + # TODO: We may be better off locking on all imports or injecting a lock + # into pickle.loads (https://github.com/ray-project/ray/issues/16304) + with self.function_actor_manager.lock: + context = self.get_serialization_context() + return context.deserialize_objects(data_metadata_pairs, + object_refs) def get_objects(self, object_refs, timeout=None): """Get the values in the object store associated with the IDs.