diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index 8d9d6f2..d15abb6 100644
a
|
b
|
|
27 | 27 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
28 | 28 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 | 29 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | | |
31 | | import os, sys, time |
32 | | |
| 30 | import os, sys, time, imp |
33 | 31 | try: |
34 | 32 | import thread |
35 | 33 | except ImportError: |
… |
… |
try:
|
42 | 40 | except ImportError: |
43 | 41 | pass |
44 | 42 | |
| 43 | try: |
| 44 | set |
| 45 | except NameError: |
| 46 | from sets import Set as set # For Python 2.3 |
45 | 47 | |
46 | 48 | RUN_RELOADER = True |
47 | 49 | |
48 | 50 | _mtimes = {} |
49 | 51 | _win = (sys.platform == "win32") |
50 | 52 | |
| 53 | def get_loaded_modules(): |
| 54 | return filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())) |
| 55 | |
| 56 | class ModuleLoaderHook: |
| 57 | __caught = set() |
| 58 | def __init__(self): |
| 59 | before = get_loaded_modules() |
| 60 | ModuleLoaderHook.__caught = set(before) |
| 61 | |
| 62 | def tracked(self): |
| 63 | return list(self.__caught) |
| 64 | |
| 65 | def find_module(self, name, path): |
| 66 | try: |
| 67 | if path: |
| 68 | name = name.split('.')[-1] |
| 69 | file, filename, _info = imp.find_module(name, path) |
| 70 | if file: |
| 71 | self.__caught.add(filename) |
| 72 | file.close() |
| 73 | except: |
| 74 | pass |
| 75 | return None #as it was not found |
| 76 | |
| 77 | loader = None |
| 78 | def hook_imports(): |
| 79 | global loader |
| 80 | loader = ModuleLoaderHook() |
| 81 | sys.meta_path.insert(0, loader) |
| 82 | |
51 | 83 | def code_changed(): |
52 | 84 | global _mtimes, _win |
53 | | for filename in filter(lambda v: v, map(lambda m: getattr(m, "__file__", None), sys.modules.values())): |
| 85 | files = get_loaded_modules() |
| 86 | if loader: |
| 87 | files = loader.tracked() |
| 88 | for filename in files: |
54 | 89 | if filename.endswith(".pyc") or filename.endswith(".pyo"): |
55 | 90 | filename = filename[:-1] |
56 | 91 | if not os.path.exists(filename): |
… |
… |
def jython_reloader(main_func, args, kwargs):
|
107 | 142 | |
108 | 143 | |
109 | 144 | def main(main_func, args=None, kwargs=None): |
| 145 | hook_imports() |
110 | 146 | if args is None: |
111 | 147 | args = () |
112 | 148 | if kwargs is None: |