Skip to content
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

Fallback for os env vars #1164

Open
vdraceil opened this issue Jul 7, 2021 · 1 comment
Open

Fallback for os env vars #1164

vdraceil opened this issue Jul 7, 2021 · 1 comment

Comments

@vdraceil
Copy link

vdraceil commented Jul 7, 2021

[watcher:test]
cmd = python test.py
numprocesses = $(circus.env.NUM_TEST_PROCESSES)

Now, if I set os.environ["NUM_TEST_PROCESSES"] = 3, I'll have 3 "test" processes running
but if that env var is not set, what happens?
can a default be provided - like $(circus.env.NUM_TEST_PROCESSES, 1) ?
there's nothing on the docs for this, but is this even possible with circus?

If I use [env] or [env:XXX] sections, those will get precedence no matter what I set in os.environ

@biozz
Copy link
Contributor

biozz commented Jul 7, 2021

Hi, @vdraceil!

Let's break it down.

but if that env var is not set, what happens?

With the config you provided - there will be an exception, because the variables are not interpolated if either [env] section or copy_env is specified.

This config should properly handle your environment variables if set.

[watcher:test]
cmd = python test.py
numprocesses = $(circus.env.NUM_TEST_PROCESSES)
copy_env = True

can a default be provided - like $(circus.env.NUM_TEST_PROCESSES, 1) ?

Unfortunately, no, there is no such feature at the moment. But it is a good suggestion. Although, it might require changing the signature of replace_gnu_args method, which can be a pain.

Another solution could be falling back to default values, not sure why it is not done yet.

there's nothing on the docs for this

I agree, the docs could use some polishing and more notes about environment variables. I will try to do something about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants