Open blueplastic opened 3 years ago
@blueplastic actor classes are instantiated across multiple processes, so each actor will have its own copy of the class variables. Therefore, using class variables is not currently supported/recommended.
We should definitely try to raise an informative error message here, though.
This document could be related
What if raising an exception when user is trying to define a class variable?
It may not be a good idea, because it breaks backward compatibility - someone may already using class variable in workers as a feature.
What if raising an exception when user is trying to define a class variable?
It may not be a good idea, because it breaks backward compatibility - someone may already using class variable in workers as a feature.
exactly. maybe introducing a global (in the concept of ray instead of python) variable decorator to the class variable would make more sense.
What is the problem?
It seems that Ray doesn't allow using a class variable to keep track of some shared class-level information, such as how many instances of the class have been created.
I understand there are at least a couple of ways I can accomplish sharing state across instances:
But I was curious about class variable support in Ray. Should class variables simply not be used? Are there any best practices around sharing state across instances?
Class variables can also make it efficient to implement default values for instance variables while avoiding the time and memory overhead of initializing that instance variable every time a class instance is created. If class variables are not supported, do we have to incur the time/memory overhead for initializing each instance variable?
Ray version: 1.0.1.post1 Python version: 3.7.8
Reproduction
If the code snippet cannot be run by itself, the issue will be closed with "needs-repro-script".