Are GODEBUG and other env vars ignored when loading a Go DLL from foreign code?

Hello,

We have a complex integration testing setup where we use Python to test data interchange between various runtimes such as Go, Java, etc. For that purpose, we compile a shared library with C-compatible entrypoints using go build -buildmode=c-shared. The shared library is then loaded and invoked at runtime using Python’s cffi library.

I’m currently trying to customize Go behavior in this integration testing setup by setting environment variables such as GOMEMLIMIT and GODEBUG before loading the Go-generated DLL. However, I get the impression that these environment variables are ignored (for example, using gctrace=1,clobberfree=1 I don’t actually get any debug output).

Is my assumption above right? If so, is there an alternative way to influence Go runtime behavior?

For reference, the related Python snippet:

Edit: I’ve started looking for clues in the Go source code and I think I get it. Like most other languages, Python’s os.environ calls the libc getenv and setenv functions to access the userspace environment. However, Go works differently: it parses the environment variables as they were set when the process was initialized (here, the Python process). Therefore, if I set environment variables from inside the Python process loading the Go DLL, the new values are not seen by Go. I have to set the environment variables form the parent process.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.