|
20 | 20 | import warnings |
21 | 21 | import numpy as np |
22 | 22 | from scipy.optimize import (minimize, LinearConstraint) |
23 | | - |
24 | 23 | from abc import ABC, abstractmethod |
| 24 | + |
| 25 | +from grid2op._glop_platform_info import _IS_WINDOWS |
25 | 26 | from grid2op.Environment._env_prev_state import _EnvPreviousState |
26 | 27 | from grid2op.Observation import (BaseObservation, |
27 | 28 | ObservationSpace, |
@@ -4117,14 +4118,25 @@ def close(self): |
4117 | 4118 | self._aux_close_local_dir_cls() |
4118 | 4119 |
|
4119 | 4120 | def _aux_close_local_dir_cls(self): |
4120 | | - if self._local_dir_cls is not None: |
4121 | | - # I am the "keeper" of the temporary directory |
4122 | | - # deleting this env should also delete the temporary directory |
4123 | | - if not (hasattr(self._local_dir_cls, "_RUNNER_DO_NOT_ERASE") and not self._local_dir_cls._RUNNER_DO_NOT_ERASE): |
4124 | | - # BUT if a runner uses it, then I should not delete it ! |
4125 | | - self._local_dir_cls.cleanup() |
4126 | | - self._local_dir_cls = None |
4127 | | - # In this case it's likely that the OS will clean it for grid2op with a warning... |
| 4121 | + if self._local_dir_cls is None: |
| 4122 | + return |
| 4123 | + # I am the "keeper" of the temporary directory |
| 4124 | + # deleting this env should also delete the temporary directory |
| 4125 | + if not (hasattr(self._local_dir_cls, "_RUNNER_DO_NOT_ERASE") and not self._local_dir_cls._RUNNER_DO_NOT_ERASE): |
| 4126 | + # BUT if a runner uses it, then I should not delete it ! |
| 4127 | + self._local_dir_cls.cleanup() |
| 4128 | + self._local_dir_cls = None |
| 4129 | + # In this case it's likely that the OS will clean it for grid2op with a warning... |
| 4130 | + |
| 4131 | + # clear all imported modules (required for windows) |
| 4132 | + # otherwise it tries to import the classes when processes are spawned |
| 4133 | + # even the classes that have been "cleaned" |
| 4134 | + if _IS_WINDOWS and type(self)._PATH_GRID_CLASSES is not None: |
| 4135 | + # TODO find a better way here |
| 4136 | + module_name = os.path.split(type(self)._PATH_GRID_CLASSES)[-1] |
| 4137 | + for el in sys.modules.copy(): |
| 4138 | + if module_name in el: |
| 4139 | + del sys.modules[el] |
4128 | 4140 |
|
4129 | 4141 | def attach_layout(self, grid_layout): |
4130 | 4142 | """ |
|
0 commit comments