(
cls,
modified_class,
actor_creation_function_descriptor,
)
| 1206 | |
| 1207 | @classmethod |
| 1208 | def create( |
| 1209 | cls, |
| 1210 | modified_class, |
| 1211 | actor_creation_function_descriptor, |
| 1212 | ): |
| 1213 | # Try to create an instance from cache. |
| 1214 | cached_meta = cls._cache.get(actor_creation_function_descriptor) |
| 1215 | if cached_meta is not None: |
| 1216 | return cached_meta |
| 1217 | |
| 1218 | # Create an instance without __init__ called. |
| 1219 | self = cls.__new__(cls) |
| 1220 | |
| 1221 | actor_methods = inspect.getmembers(modified_class, is_function_or_method) |
| 1222 | self.methods = dict(actor_methods) |
| 1223 | |
| 1224 | # Extract the signatures of each of the methods. This will be used |
| 1225 | # to catch some errors if the methods are called with inappropriate |
| 1226 | # arguments. |
| 1227 | self.decorators = {} |
| 1228 | self.signatures = {} |
| 1229 | self.num_returns = {} |
| 1230 | self.max_task_retries = {} |
| 1231 | self.retry_exceptions = {} |
| 1232 | self.method_is_generator = {} |
| 1233 | self.enable_task_events = {} |
| 1234 | self.generator_backpressure_num_objects = {} |
| 1235 | self.concurrency_group_for_methods = {} |
| 1236 | self.method_name_to_tensor_transport: Dict[str, str] = {} |
| 1237 | |
| 1238 | # Check whether any actor methods specify a non-default tensor transport. |
| 1239 | self.has_tensor_transport_methods = any( |
| 1240 | getattr( |
| 1241 | method, |
| 1242 | "__ray_tensor_transport__", |
| 1243 | None, |
| 1244 | ) |
| 1245 | is not None |
| 1246 | for _, method in actor_methods |
| 1247 | ) |
| 1248 | |
| 1249 | for method_name, method in actor_methods: |
| 1250 | # Whether or not this method requires binding of its first |
| 1251 | # argument. For class and static methods, we do not want to bind |
| 1252 | # the first argument, but we do for instance methods |
| 1253 | method = inspect.unwrap(method) |
| 1254 | is_bound = is_class_method(method) or is_static_method( |
| 1255 | modified_class, method_name |
| 1256 | ) |
| 1257 | |
| 1258 | # Print a warning message if the method signature is not |
| 1259 | # supported. We don't raise an exception because if the actor |
| 1260 | # inherits from a class that has a method whose signature we |
| 1261 | # don't support, there may not be much the user can do about it. |
| 1262 | self.signatures[method_name] = signature.extract_signature( |
| 1263 | method, ignore_first=not is_bound |
| 1264 | ) |
| 1265 | # Set the default number of return values for this method. |
no test coverage detected