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
I’m currently trying to customize Go behavior in this integration testing setup by setting environment variables such as
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
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.