Uncache a module from sys.modules. A basic sanity check is performed to prevent uncaching modules that either cannot/shouldn't be uncached.
(*names)
| 143 | |
| 144 | @contextlib.contextmanager |
| 145 | def uncache(*names): |
| 146 | """Uncache a module from sys.modules. |
| 147 | |
| 148 | A basic sanity check is performed to prevent uncaching modules that either |
| 149 | cannot/shouldn't be uncached. |
| 150 | |
| 151 | """ |
| 152 | for name in names: |
| 153 | if name in ('sys', 'marshal'): |
| 154 | raise ValueError("cannot uncache {}".format(name)) |
| 155 | try: |
| 156 | del sys.modules[name] |
| 157 | except KeyError: |
| 158 | pass |
| 159 | try: |
| 160 | yield |
| 161 | finally: |
| 162 | for name in names: |
| 163 | try: |
| 164 | del sys.modules[name] |
| 165 | except KeyError: |
| 166 | pass |
| 167 | |
| 168 | |
| 169 | @contextlib.contextmanager |
searching dependent graphs…