Skip to content

Commit 9c992c9

Browse files
authored
feat: add LISTEN_ADDRESS to Python default runner (knative#2880)
1 parent 56e1b0f commit 9c992c9

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

pkg/functions/runner.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ func runPython(ctx context.Context, job *Job) (err error) {
240240
}
241241

242242
// Run
243+
listenAddress := net.JoinHostPort(job.Host, job.Port)
243244
if job.verbose {
244-
fmt.Printf("PORT=%v ./.venv/bin/python ./service/main.py\n", job.Port)
245+
fmt.Printf("PORT=%v LISTEN_ADDRESS=%v ./.venv/bin/python ./service/main.py\n", job.Port, listenAddress)
245246
}
246247
cmd = exec.CommandContext(ctx, "./.venv/bin/python", "./service/main.py")
247248
// cmd.Dir = job.Function.Root // handled by the middleware
@@ -254,7 +255,7 @@ func runPython(ctx context.Context, job *Job) (err error) {
254255
// PWD environment variable for the subprocess to match Dir.
255256
// The new method Cmd.Environ reports the environment that would be used
256257
// to run the command, including the implicitly set PWD variable.
257-
cmd.Env = append(cmd.Env, "PORT="+job.Port, "PWD="+cmd.Dir)
258+
cmd.Env = append(cmd.Env, "PORT="+job.Port, "LISTEN_ADDRESS="+listenAddress, "PWD="+cmd.Dir)
258259

259260
// Running asynchronously allows for the client Run method to return
260261
// metadata about the running function such as its chosen port.

0 commit comments

Comments
 (0)