diff --git a/flexbe_onboard/src/flexbe_onboard/flexbe_onboard.py b/flexbe_onboard/src/flexbe_onboard/flexbe_onboard.py index a074aa4e..9254833d 100644 --- a/flexbe_onboard/src/flexbe_onboard/flexbe_onboard.py +++ b/flexbe_onboard/src/flexbe_onboard/flexbe_onboard.py @@ -281,16 +281,17 @@ def _is_switchable(self, be): def _cleanup_behavior(self, behavior_checksum): - del(sys.modules["tmp_%d" % behavior_checksum]) - file_path = os.path.join(self._tmp_folder, 'tmp_%d.pyc' % behavior_checksum) + module_name = "tmp_%d" % behavior_checksum try: + module = sys.modules[module_name] + file_path = module.__file__ + del sys.modules[module_name] + except KeyError: + return + if os.path.exists(file_path): os.remove(file_path) - except OSError: - pass - try: + if os.path.exists(file_path + 'c'): os.remove(file_path + 'c') - except OSError: - pass def _cleanup_tempdir(self):