Edgewall Software

Ticket #9602: 9602.fix-autoreload-for-bad-plugins.2.diff

File 9602.fix-autoreload-for-bad-plugins.2.diff, 1.9 KB (added by anatoly techtonik <techtonik@…>, 17 months ago)

do not add files several times

  • trac/loader.py

     
    2222import os 
    2323import sys 
    2424 
     25from trac.util.autoreload import _AUTORELOAD_EXTRA_FILES 
    2526from trac.util.compat import set 
    2627from trac.util.text import exception_to_unicode 
    2728 
     
    9596                    env.log.error('Failed to load plugin from %s: %s', 
    9697                                  plugin_file, 
    9798                                  exception_to_unicode(e, traceback=True)) 
     99                    # add failed plugin to the list of monitored files 
     100                    # in autoreload mode for development 
     101                    if plugin_file not in _AUTORELOAD_EXTRA_FILES: 
     102                        _AUTORELOAD_EXTRA_FILES.append(plugin_file) 
    98103 
    99104    return _load_py_files 
    100105 
  • trac/util/autoreload.py

     
    1515import sys 
    1616import thread 
    1717import time 
     18import itertools 
    1819 
    1920_SLEEP_TIME = 1 
     21_AUTORELOAD_EXTRA_FILES = [] 
    2022 
    2123def _reloader_thread(modification_callback): 
    2224    """When this function is run from the main thread, it will force other 
     
    2729    """ 
    2830    mtimes = {} 
    2931    while True: 
    30         for filename in filter(None, [getattr(module, '__file__', None) 
    31                                       for module in sys.modules.values()]): 
     32        for filename in itertools.chain( 
     33            filter(None, [getattr(module, '__file__', None) 
     34                          for module in sys.modules.values()]), 
     35            _AUTORELOAD_EXTRA_FILES 
     36          ): 
    3237            while not os.path.isfile(filename): # Probably in an egg or zip file 
    3338                filename = os.path.dirname(filename) 
    3439                if not filename: