Question: I have a c-extension that loads environment variables during static initialization. I need to be able to change these values and reload the module (I cannot change the fact that they are loaded statically). I tried setting `os.environ`, but there doesn't seem to be an `env` option in `importlib` like for `subprocess.call`

Here's an example: suppose I have a module defined as follows

```
#include <boost/python.hpp>
#include <cstdlib>
#include <string>
std::string get() {
    return ::getenv("HOME");
}

BOOST_PYTHON_MODULE(sample) {
    boost::python::def("get", &get);
}

```

And I have python code:

```
import importlib, os
import sample as s
print(s.get()) # prints /home/username

# do something like 
# os.environ['HOME'] = 'foo'
importlib.reload(s)
print(s.get()) # I would like this to print 'foo'

```

In other words, what can I do instead of `os.environ['HOME'] = 'foo'` to cause the environment variable to change in the c-module?

**NOTE**: I cannot use `setenv` because the variables are loaded statically and I am unable to reinitializes all the things that depend on them.

Answer: 
If I am not mistaken, the reason this does not work is not because the environment is not modified but because when you do `importlib.reload(s)` [the c module is not actually re-initialized](http://bugs.python.org/issue1144263).

What you can do is put your calls to s in another process, and whenever you need to reload it create a new process.
Maybe you can do something with Py\_Finalize and Py\_Initialize in your or a second c extension that will replace your module reload? But it's maybe an overkill...?