Skip to content

Commit

Permalink
Autoreloader must reload from cwd
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Feb 23, 2012
1 parent 439a566 commit 0c75d4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 8 additions & 1 deletion celery/utils/__init__.py
Expand Up @@ -34,7 +34,7 @@
uuid = gen_unique_id

from ..exceptions import CPendingDeprecationWarning, CDeprecationWarning
from .compat import StringIO
from .compat import StringIO, reload

LOG_LEVELS = dict(logging._levelNames)
LOG_LEVELS["FATAL"] = logging.FATAL
Expand Down Expand Up @@ -392,6 +392,13 @@ def import_from_cwd(module, imp=None, package=None):
return imp(module, package=package)


def reload_from_cwd(module, reloader=None):
if reloader is None:
reloader = reload
with cwd_in_path():
return reloader(module)


def cry(): # pragma: no cover
"""Return stacktrace of all active threads.
Expand Down
6 changes: 2 additions & 4 deletions celery/worker/__init__.py
Expand Up @@ -30,8 +30,7 @@
from ..app.abstract import configurated, from_config
from ..exceptions import SystemTerminate
from ..log import SilenceRepeated
from ..utils import noop, qualname
from ..utils.compat import reload as _reload
from ..utils import noop, qualname, reload_from_cwd

from . import state
from .buckets import TaskBucket, FastQueue
Expand Down Expand Up @@ -297,7 +296,6 @@ def _shutdown(self, warm=True):
self._shutdown_complete.set()

def reload(self, modules=None, reload=False, reloader=None):
reloader = _reload if reloader is None else reloader
modules = self.app.loader.task_modules if modules is None else modules
imp = self.app.loader.import_from_cwd

Expand All @@ -307,7 +305,7 @@ def reload(self, modules=None, reload=False, reloader=None):
imp(module)
elif reload:
self.logger.debug("reloading module %s" % (module, ))
reloader(sys.modules[module])
reload_from_cwd(sys.modules[module], reloader)
self.pool.restart()

def on_timer_error(self, einfo):
Expand Down

0 comments on commit 0c75d4b

Please sign in to comment.