-
Notifications
You must be signed in to change notification settings - Fork 5
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
changing default WorkerContext #327
Comments
Certainly the defaults are arbitrary, and in my main use-case I do exactly as you suggest, throwing the context into the module globals. It works, but it's definitely awkward. The trouble with modifying the default context is the cross-run shared semantics that I imposed on it. A subsequent (or concurrent!) trio run will inherit whatever default context has been assigned, and the code running at that time may be expecting the default behaviors. Some kind of guard rail for this case would be nice. During the construction of the Nevertheless, maybe we can find some minimal way to change the parameters that isn't too confusing or destructive. Can you try in your own application simply assigning to the private global variable before startup: import trio_parallel._impl
trio_parallel._impl.DEFAULT_CONTEXT = WorkerContext._create(**options) and let me know if it has any weird knock-on effects for you? If all's well then I can cook up an API to do this in a way that preserves platform-parity (that code won't work on windows) and also ensures every process spawned by the previous default context gets reaped. |
I think it would be OK for Until someone says "I need to change the default config on the fly", and is going to fund it, there is no need to take it on... |
seems to work OK for now, thank you |
Could you check #328 as well? |
#328 seems to work OK, thank you It was a little frustrating that |
After a bit of refactoring, it now works inside a trio run. (Actually only inside a trio run on Windows!) The main thread restriction is also a bit artificial, it's just so I don't have to worry about thread races. Any thoughts about that? I can cut a beta release to pypi if you are interested in moving quickly on this. |
thank you-- I tried the update, setting from trio.run(), and it works OK I'll probably keep the old workaround until there is a regular release, no need for a beta in pypi on this end |
It would be nice to have a way to change the default WorkerContext, for example:
I'd like to change the idle timeout globally. Currently, I'd have to open a worker context at the root nursery, and store that into a contextvar or something, and hope that everyone remembers to use that context.
The default parameters of
WorkerContext
are quite arbitrary, so I think it would make sense to have a way to change the default context.The text was updated successfully, but these errors were encountered: