Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

get bs_module from sys.modules, not directly from __import__()

__import__ returns the top-level module of a package, not the module itself.
  • Loading branch information...
commit a89419f99c8ace05ba2082457c0b8d6be096a188 1 parent a9f6be7
@bmathieu33 bmathieu33 authored
View
10 django_beanstalkd/decorators.py
@@ -1,3 +1,6 @@
+# -*- coding: utf-8 -*-
+import sys
+
class beanstalk_job(object):
"""
Decorator marking a function inside some_app/beanstalk_jobs.py as a
@@ -5,9 +8,11 @@ class beanstalk_job(object):
"""
def __init__(self, f):
+ modname = f.__module__
self.f = f
self.__name__ = f.__name__
-
+ self.__module__ = modname
+
# determine app name
parts = f.__module__.split('.')
if len(parts) > 1:
@@ -16,7 +21,8 @@ def __init__(self, f):
self.app = ''
# store function in per-app job list (to be picked up by a worker)
- bs_module = __import__(f.__module__)
+ __import__(modname)
+ bs_module = sys.modules[modname]
try:
if self not in bs_module.beanstalk_job_list:
bs_module.beanstalk_job_list.append(self)
View
8 django_beanstalkd/management/commands/beanstalk_worker.py
@@ -33,7 +33,9 @@ def handle_noargs(self, **options):
bs_modules = []
for app in settings.INSTALLED_APPS:
try:
- bs_modules.append(__import__("%s.beanstalk_jobs" % app))
+ modname = "%s.beanstalk_jobs" % app
+ __import__(modname)
+ bs_modules.append(sys.modules[modname])
except ImportError:
pass
if not bs_modules:
@@ -108,7 +110,7 @@ def work(self):
for job in self.jobs.keys():
beanstalk.watch(job)
beanstalk.ignore('default')
-
+
try:
while True:
job = beanstalk.reserve()
@@ -133,6 +135,6 @@ def work(self):
job.delete()
else:
job.release()
-
+
except KeyboardInterrupt:
sys.exit(0)
Please sign in to comment.
Something went wrong with that request. Please try again.