ENH: Set environment in try/finally

To avoid situations in wich the flag is not unset
Merge pull request #104 from GaelVaroquaux/safe_environment_flag

ENH: Set environment in try/finally