Skip to content

Enable config to be used as context manager - #7363

Merged
rossbar merged 5 commits into
networkx:mainfrom
eriknw:config_context
Jul 3, 2024
Merged

rossbar merged 5 commits into
networkx:mainfrom
eriknw:config_context

Conversation

@eriknw

@eriknw eriknw commented Mar 22, 2024

Copy link
Copy Markdown
Contributor

Small enhancement to config to allow it to be used with with ...:.

CC @rossbar, weren't you interested in using context managers? For example (and CC @Schefflera-Arboricola):

with nx.config.backends.parallel(n_jobs=8):
    ...

Our config uses a simple stack to handle contexts and is unapologetically global. It does not even attempt to work well in multithreaded code via thread locals or async code via context variables (and trying to support both is non-trivial, so applications should roll their own solutions as necessary). #7345 actually adds a note to the config docs about this:

This is a global configuration. Use with caution when using from multiple threads.

@rossbar rossbar added the Dispatching Related to dispatching and backend support label Apr 8, 2024

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this -- having context managing capabilities is a real plus for a config tool.

This interface seems natural, the tests are nice, seems like a straight-foward improvement to the config interface. I approve this PR.

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eriknw , sorry it took so long for me to look at this 🙃 .

This LGTM and indeed I really like the feature!

@rossbar
rossbar merged commit a798b2e into networkx:main Jul 3, 2024
@jarrodmillman jarrodmillman added this to the 3.4 milestone Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dispatching Related to dispatching and backend support type: Enhancements

Development

Successfully merging this pull request may close these issues.

4 participants