-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathunload_pkgs.py
More file actions
28 lines (23 loc) · 806 Bytes
/
Copy pathunload_pkgs.py
File metadata and controls
28 lines (23 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#-*- coding: utf-8 -*-
import sys
# if you have some packages that you often reload, you can put them here
# and they will get reloaded if "packages" attribute is not explicitly stated
DEFAULT_RELOAD_PACKAGES = []
def unload_packages(silent=True, packages=None):
if packages is None:
packages = DEFAULT_RELOAD_PACKAGES
# construct reload list
reloadList = []
for i in sys.modules.keys():
for package in packages:
if i.startswith(package):
reloadList.append(i)
# unload everything
for i in reloadList:
try:
if sys.modules[i] is not None:
del(sys.modules[i])
if not silent:
print("Unloaded: %s" % i)
except:
print("Failed to unload: %s" % i)