-
Notifications
You must be signed in to change notification settings - Fork 540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REVIEW] Ensure global_output_type is thread-safe #3497
[REVIEW] Ensure global_output_type is thread-safe #3497
Conversation
Ensure that standard ways of manipulating global_output_type are thread-safe
Create thread-local borg object to store global settings including global_output_type in a thread-safe way
Avoid initializing root_cm on one thread only by using thread-local borg object
A few notes for those reviewing:
|
Since there hasn't been any comment on this and offline discussion was generally positive for deprecating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of minor suggestions and one request. I like the new system for global settings. I think it could be very flexible and make debugging issues easier. For example, what do you think about adding to global_settings.py
a logging wrapper:
class LoggingGlobalSettings(GlobalSettings):
@GlobalSettings.output_type.setter
def output_type(self, value):
print("Setting `output_type` = {}".format(value))
self._output_type = value
And then this could be controlled with an environment variable:
class GlobalSettings(object):
def __new__(cls):
if ("CUML_DEBUG_GLOBALSETTINGS" in os.environ):
return super(GlobalSettings, cls).__new__(LoggingGlobalSettings)
else:
return super(GlobalSettings, cls).__new__(cls)
def __init__(self):
self.__dict__ = _global_settings_data.shared_state
This is just an example, but the idea would be great to add to this PR. Let me know what you think.
I also have one request: Can you move the aliased decorators in api_decorators.py
(everything below line 657) into a separate file so they can be discovered easily? This has been on my todo list and would fit well with this PR.
Other than that, the PR looks great. Love the Dask tests.
Co-authored-by: Michael Demoret <[email protected]>
If it's all right by you, I'd like to leave this for another PR if we decide to include it. I think this might be one case where "less is more" in terms of providing debugging tools for the team. Adding something controlled by an environment variable that deep in the guts of the code does not necessarily seem like the right way to approach this. If someone gets to the point where they know they need to understand how the output type is being set and changed, they'll probably be looking at the global settings code anyway, and it's easy enough to set a breakpoint or (if we must! ;) ) add a logging statement. If someone sets the environment variable and starts to follow the logic of how the output types are getting changed, they're probably at a point where they'll need problem-specific debugging code anyway. All that being said, I'm happy to be overruled if other people think this would be a handy, often-used tool. Even then, though, I think it would be worth deferring to a separate PR, since there could be useful discussion about the details of the implementation. For instance, I don't think I'd necessarily jump to overriding |
Fair enough. Your implementation looks great and sparked some ideas but I agree with your assessment. Better to leave it for another PR, if one is even necessary. |
I started to do this, but then I wasn't quite sure about what should and shouldn't be moved over. Everything under 657 or just the aliases? Would you mind terribly just popping that into its own PR? It seems like a discrete change, and I want to make sure it's exactly what you're looking for. I'd be happy to give it a quick review! |
No problem. I have it on my TODO list already. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Nice improvement.
@gpucibot merge |
Introduce a global_settings object implemented as a thread-local borg for storing global settings in a thread-safe way
Ensure that global_output_type is manipulated only in thread-safe ways and provide associated unit tests
Move "root" context manager to global_settings object to avoid unnecessary existence check for root_cm
Close #3234
Mitigate #3237