Ask Solem 15 tahun lalu
induk
melakukan
5969b706ae

+ 11 - 10
celery/backends/cache.py

@@ -4,27 +4,28 @@ from django.core.cache.backends.base import InvalidCacheBackendError
 from django.utils.encoding import smart_str
 from celery.backends.base import KeyValueStoreBackend
 
+
 class DjangoMemcacheWrapper(object):
-    """
-    Wrapper class to django's memcache backend class, that overrides the get method in
-    order to remove the forcing of unicode strings since it may cause binary or pickled data
-    to break.
-    """
+    """Wrapper class to django's memcache backend class, that overrides the
+    :meth:`get` method in order to remove the forcing of unicode strings
+    since it may cause binary or pickled data to break."""
+
     def __init__(self, cache):
         self.cache = cache
-    
+
     def get(self, key, default=None):
         val = self.cache._cache.get(smart_str(key))
         if val is None:
             return default
         else:
             return val
-    
+
     def set(self, key, value, timeout=0):
         self.cache.set(key, value, timeout)
 
-# Check if django is using memcache as the cache backend. If so, wrap the cache object in
-# our DjangoMemcacheWrapper that fixes a bug with retrieving pickled data
+# Check if django is using memcache as the cache backend. If so, wrap the
+# cache object in a DjangoMemcacheWrapper that fixes a bug with retrieving
+# pickled data
 try:
     from django.core.cache.backends.memcached import CacheClass
     if isinstance(cache, CacheClass):
@@ -40,4 +41,4 @@ class Backend(KeyValueStoreBackend):
         return cache.get(key)
 
     def set(self, key, value):
-        cache.set(key, value)
+        cache.set(key, value)

+ 1 - 1
celery/bin/celeryd.py

@@ -189,7 +189,7 @@ def run_worker(concurrency=DAEMON_CONCURRENCY, detach=False,
 
     if hasattr(signal, "SIGCLD"): # Make sure the platform supports signals.
         signal.signal(signal.SIGCLD, signal.SIG_DFL)
-    
+
     print("Celery %s is starting." % __version__)
 
     if statistics is not None:

+ 0 - 1
celery/bin/celeryinit.py

@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 
 
 def main():

+ 40 - 37
celery/fields.py

@@ -12,30 +12,32 @@ from celery.seralization import pickle
 from django.db import models
 from django.utils.encoding import force_unicode
 
+
 class PickledObject(str):
-    """
-    A subclass of string so it can be told whether a string is a pickled
+    """A subclass of string so it can be told whether a string is a pickled
     object or not (if the object is an instance of this class then it must
     [well, should] be a pickled one).
-    
+
     Only really useful for passing pre-encoded values to ``default``
     with ``dbsafe_encode``, not that doing so is necessary. If you
     remove PickledObject and its references, you won't be able to pass
     in pre-encoded values anymore, but you can always just pass in the
     python objects themselves.
-    
+
     """
     pass
 
+
 def dbsafe_encode(value, compress_object=False):
-    """
-    We use deepcopy() here to avoid a problem with cPickle, where dumps
+    """We use deepcopy() here to avoid a problem with cPickle, where dumps
     can generate different character streams for same lookup value if
-    they are referenced differently. 
-    
+    they are referenced differently.
+
     The reason this is important is because we do all of our lookups as
     simple string matches, thus the character streams must be the same
-    for the lookups to work properly. See tests.py for more information.
+    for the lookups to work properly. See tests.py for more
+    information.
+
     """
     if not compress_object:
         value = b64encode(pickle.dumps(deepcopy(value)))
@@ -43,6 +45,7 @@ def dbsafe_encode(value, compress_object=False):
         value = b64encode(compress(pickle.dumps(deepcopy(value))))
     return PickledObject(value)
 
+
 def dbsafe_decode(value, compress_object=False):
     if not compress_object:
         value = pickle.loads(b64decode(value))
@@ -50,39 +53,38 @@ def dbsafe_decode(value, compress_object=False):
         value = pickle.loads(decompress(b64decode(value)))
     return value
 
+
 class PickledObjectField(models.Field):
-    """
-    A field that will accept *any* python object and store it in the
+    """A field that will accept *any* python object and store it in the
     database. PickledObjectField will optionally compress it's values if
     declared with the keyword argument ``compress=True``.
-    
+
     Does not actually encode and compress ``None`` objects (although you
     can still do lookups using None). This way, it is still possible to
     use the ``isnull`` lookup type correctly. Because of this, the field
     defaults to ``null=True``, as otherwise it wouldn't be able to store
     None values since they aren't pickled and encoded.
-    
+
     """
     __metaclass__ = models.SubfieldBase
-    
+
     def __init__(self, *args, **kwargs):
         self.compress = kwargs.pop('compress', False)
         self.protocol = kwargs.pop('protocol', 2)
         kwargs.setdefault('null', True)
         kwargs.setdefault('editable', False)
         super(PickledObjectField, self).__init__(*args, **kwargs)
-    
+
     def get_default(self):
-        """
-        Returns the default value for this field.
-        
+        """Returns the default value for this field.
+
         The default implementation on models.Field calls force_unicode
         on the default, which means you can't set arbitrary Python
         objects as the default. To fix this, we just return the value
         without calling force_unicode on it. Note that if you set a
         callable as a default, the field will still call it. It will
         *not* try to pickle and encode it.
-        
+
         """
         if self.has_default():
             if callable(self.default):
@@ -92,15 +94,15 @@ class PickledObjectField(models.Field):
         return super(PickledObjectField, self).get_default()
 
     def to_python(self, value):
-        """
-        B64decode and unpickle the object, optionally decompressing it.
-        
+        """B64decode and unpickle the object, optionally decompressing it.
+
         If an error is raised in de-pickling and we're sure the value is
         a definite pickle, the error is allowed to propogate. If we
         aren't sure if the value is a pickle or not, then we catch the
         error and return the original value instead.
-        
+
         """
+
         if value is not None:
             try:
                 value = dbsafe_decode(value, self.compress)
@@ -112,23 +114,23 @@ class PickledObjectField(models.Field):
         return value
 
     def get_db_prep_value(self, value):
-        """
-        Pickle and b64encode the object, optionally compressing it.
-        
+        """Pickle and b64encode the object, optionally compressing it.
+
         The pickling protocol is specified explicitly (by default 2),
         rather than as -1 or HIGHEST_PROTOCOL, because we don't want the
         protocol to change over time. If it did, ``exact`` and ``in``
         lookups would likely fail, since pickle would now be generating
-        a different string. 
-        
+        a different string.
+
         """
+
         if value is not None and not isinstance(value, PickledObject):
-            # We call force_unicode here explicitly, so that the encoded string
-            # isn't rejected by the postgresql_psycopg2 backend. Alternatively,
-            # we could have just registered PickledObject with the psycopg
-            # marshaller (telling it to store it like it would a string), but
-            # since both of these methods result in the same value being stored,
-            # doing things this way is much easier.
+            # We call force_unicode here explicitly, so that the encoded
+            # string isn't rejected by the postgresql_psycopg2 backend.
+            # Alternatively, we could have just registered PickledObject with
+            # the psycopg marshaller (telling it to store it like it would a
+            # string), but since both of these methods result in the same
+            # value being stored, doing things this way is much easier.
             value = force_unicode(dbsafe_encode(value, self.compress))
         return value
 
@@ -136,12 +138,13 @@ class PickledObjectField(models.Field):
         value = self._get_val_from_obj(obj)
         return self.get_db_prep_value(value)
 
-    def get_internal_type(self): 
+    def get_internal_type(self):
         return 'TextField'
-    
+
     def get_db_prep_lookup(self, lookup_type, value):
         if lookup_type not in ['exact', 'in', 'isnull']:
             raise TypeError('Lookup type %s is not supported.' % lookup_type)
         # The Field model already calls get_db_prep_value before doing the
         # actual lookup, so all we need to do is limit the lookup types.
-        return super(PickledObjectField, self).get_db_prep_lookup(lookup_type, value)
+        return super(PickledObjectField, self).get_db_prep_lookup(lookup_type,
+                                                                  value)

+ 8 - 7
celery/loaders/__init__.py

@@ -23,13 +23,14 @@ else:
         # used configuration method so to propogate it to the "child"
         # processes. But this has to be experimented with.
         # [asksol/heyman]
-    try:
-        settings_mod = os.environ.get("DJANGO_SETTINGS_MODULE", "settings")
-        project_settings = __import__(settings_mod, {}, {}, [''])
-        setup_environ(project_settings)
-        Loader = DjangoLoader
-    except ImportError:
-        pass
+        try:
+            settings_mod = os.environ.get("DJANGO_SETTINGS_MODULE",
+                                          "settings")
+            project_settings = __import__(settings_mod, {}, {}, [''])
+            setup_environ(project_settings)
+            Loader = DjangoLoader
+        except ImportError:
+            pass
 
 """
 .. data:: current_loader

+ 1 - 1
celery/log.py

@@ -105,7 +105,7 @@ class LoggingProxy(object):
 
             handler.handleError = WithSafeHandleError().handleError
 
-        return map(wrap_handler, self.logger.handlers)            
+        return map(wrap_handler, self.logger.handlers)
 
     def write(self, data):
         """Write message to logging object."""

+ 1 - 2
celery/models.py

@@ -73,9 +73,8 @@ class PeriodicTaskMeta(models.Model):
         return tasks[self.name]
 
 
-
-# keep models away from syncdb/reset if database backend is not being used.
 if (django.VERSION[0], django.VERSION[1]) >= (1, 1):
+    # keep models away from syncdb/reset if database backend is not being used.
     if conf.CELERY_BACKEND != 'database':
         TaskMeta._meta.managed = False
     if conf.CELERY_PERIODIC_STATUS_BACKEND != 'database':

+ 0 - 3
celery/pool.py

@@ -65,9 +65,6 @@ def process_is_dead(process):
     :returns: ``True`` if the process is not running, ``False`` otherwise.
 
     """
-    
-    # Try to see if the process is actually running,
-    # and reap zombie proceses while we're at it.
 
     # Only do this if os.kill exists for this platform (e.g. Windows doesn't
     # support it).

+ 1 - 0
celery/serialization.py

@@ -105,6 +105,7 @@ def get_pickleable_exception(exc):
         return excwrapper
     return exc
 
+
 def get_pickled_exception(exc):
     """Get original exception from exception pickled using
     :meth:`get_pickleable_exception`."""

+ 1 - 1
celery/task/base.py

@@ -368,7 +368,7 @@ class Task(object):
         :param task_id: Unique id of the failed task.
         :param args: Original arguments for the task that failed.
         :param kwargs: Original keyword arguments for the task that failed.
-        
+
         The return value of this handler is ignored.
 
         """

+ 6 - 4
celery/task/rest.py

@@ -25,7 +25,7 @@ class URL(object):
     """Object wrapping a Uniform Resource Locator.
 
     Supports editing the query parameter list.
-    You can convert the object back to a string, the query will be 
+    You can convert the object back to a string, the query will be
     properly urlencoded.
 
     Examples
@@ -45,12 +45,14 @@ class URL(object):
     def __init__(self, url):
         self.url = urlparse(url)
         self._query = dict(parse_qsl(self.url.query))
-    
+
     def _utf8dict(self, tuple_):
+
         def value_encode(val):
             if isinstance(val, unicode):
                 return val.encode("utf-8")
             return val
+
         return dict((key.encode("utf-8"), value_encode(value))
                         for key, value in tuple_)
 
@@ -107,7 +109,7 @@ class RESTProxy(object):
             payload = deserialize(response)
         except ValueError, exc:
             raise InvalidResponseError(str(exc))
-   
+
         # {"status": "success", "retval": 300}
         # {"status": "failure": "reason": "Invalid moon alignment."}
         status = payload["status"]
@@ -148,7 +150,7 @@ def task_response(fun, *args, **kwargs):
         response = {"status": "success", "retval": retval}
 
     return serialize(response)
-    
+
 
 class Task(BaseTask):
 

+ 1 - 0
celery/tests/test_backends/test_tyrant.py

@@ -19,6 +19,7 @@ class SomeClass(object):
 
 
 def get_tyrant_or_None():
+
     def emit_no_tyrant_msg():
         global _no_tyrant_msg_emitted
         if not _no_tyrant_msg_emitted:

+ 0 - 1
celery/tests/test_monitoring.py

@@ -81,7 +81,6 @@ class TestStatsCollector(unittest.TestCase):
         for timer in (timer1, timer2, timer3):
             timer.stop()
 
-
         # Collect
         self.s.collect()
         self.assertEquals(self.s.total_tasks_processed, 3)

+ 0 - 3
celery/tests/test_pickle.py

@@ -14,11 +14,8 @@ class ArgOverrideException(Exception):
 
 
 class TestPickle(unittest.TestCase):
-    # See: http://www.reddit.com/r/django/comments/8gdwi/
-    #      celery_distributed_task_queue_for_django/c097hr1
 
     def test_pickle_regular_exception(self):
-
         e = None
         try:
             raise RegularException("RegularException raised")

+ 0 - 1
celery/worker/job.py

@@ -12,7 +12,6 @@ import multiprocessing
 import socket
 import sys
 
-
 # pep8.py borks on a inline signature separator and
 # says "trailing whitespace" ;)
 EMAIL_SIGNATURE_SEP = "-- "

+ 0 - 5
docs/_ext/literals_to_xrefs.py

@@ -108,11 +108,6 @@ def fixliterals(fname):
     storage["lastvalues"] = lastvalues
     storage.close()
 
-#
-# The following is taken from django.utils.termcolors and is copied here to
-# avoid the dependancy.
-#
-
 
 def colorize(text='', opts=(), **kwargs):
     """

+ 0 - 111
docs/conf.py

@@ -27,9 +27,6 @@ templates_path = ['.templates']
 # The suffix of source filenames.
 source_suffix = '.rst'
 
-# The encoding of source files.
-#source_encoding = 'utf-8'
-
 # The master toctree document.
 master_doc = 'index'
 
@@ -46,139 +43,31 @@ version = ".".join(map(str, celery.VERSION[0:2]))
 # The full version, including alpha/beta/rc tags.
 release = celery.version_with_meta()
 
-# The language for content autogenerated by Sphinx. Refer to documentation
-# for a list of supported languages.
-#language = None
-
-# There are two options for replacing |today|: either, you set today to some
-# non-false value, then it is used:
-#today = ''
-# Else, today_fmt is used as the format for a strftime call.
-#today_fmt = '%B %d, %Y'
-
-# List of documents that shouldn't be included in the build.
-#unused_docs = []
-
-# List of directories, relative to source directory, that shouldn't be searched
-# for source files.
 exclude_trees = ['.build']
 
-
 # If true, '()' will be appended to :func: etc. cross-reference text.
 add_function_parentheses = True
 
-# If true, the current module name will be prepended to all description
-# unit titles (such as .. function::).
-#add_module_names = True
-
-# If true, sectionauthor and moduleauthor directives will be shown in the
-# output. They are ignored by default.
-#show_authors = False
-
 # The name of the Pygments (syntax highlighting) style to use.
 pygments_style = 'trac'
 
-#html_translator_class = "djangodocs.DjangoHTMLTranslator"
-
-
-# Options for HTML output
-# -----------------------
-
-# The style sheet to use for HTML and HTML Help pages. A file of that name
-# must exist either in Sphinx' static/ path, or in one of the custom paths
-# given in html_static_path.
-#html_style = 'agogo.css'
-
-# The name for this set of Sphinx documents.  If None, it defaults to
-# "<project> v<release> documentation".
-#html_title = None
-
-# A shorter title for the navigation bar.  Default is the same as html_title.
-#html_short_title = None
-
-# The name of an image file (relative to this directory) to place at the top
-# of the sidebar.
-#html_logo = None
-
-# The name of an image file (within the static path) to use as favicon of the
-# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
-# pixels large.
-#html_favicon = None
-
 # Add any paths that contain custom static files (such as style sheets) here,
 # relative to this directory. They are copied after the builtin static files,
 # so a file named "default.css" will overwrite the builtin "default.css".
 html_static_path = ['.static']
 
-# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
-# using the given strftime format.
-#html_last_updated_fmt = '%b %d, %Y'
-
-# If true, SmartyPants will be used to convert quotes and dashes to
-# typographically correct entities.
 html_use_smartypants = True
 
-# Custom sidebar templates, maps document names to template names.
-#html_sidebars = {}
-
-# Additional templates that should be rendered to pages, maps page names to
-# template names.
-#html_additional_pages = {}
-
 # If false, no module index is generated.
 html_use_modindex = True
 
 # If false, no index is generated.
 html_use_index = True
 
-# If true, the index is split into individual pages for each letter.
-#html_split_index = False
-
-# If true, the reST sources are included in the HTML build as _sources/<name>.
-#html_copy_source = True
-
-# If true, an OpenSearch description file will be output, and all pages will
-# contain a <link> tag referring to it.  The value of this option must be the
-# base URL from which the finished HTML is served.
-#html_use_opensearch = ''
-
-# If nonempty, this is the file name suffix for HTML files (e.g. ".xhtml").
-#html_file_suffix = ''
-
-# Output file base name for HTML help builder.
-htmlhelp_basename = 'Celerydoc'
-
-
-# Options for LaTeX output
-# ------------------------
-
-# The paper size ('letter' or 'a4').
-#latex_paper_size = 'letter'
-
-# The font size ('10pt', '11pt' or '12pt').
-#latex_font_size = '10pt'
-
 latex_documents = [
   ('index', 'Celery.tex', ur'Celery Documentation',
    ur'Ask Solem', 'manual'),
 ]
 
-# The name of an image file (relative to this directory) to place at the top of
-# the title page.
-#latex_logo = None
-
-# For "manual" documents, if this is true, then toplevel headings are parts,
-# not chapters.
-#latex_use_parts = False
-
-# Additional stuff for the LaTeX preamble.
-#latex_preamble = ''
-
-# Documents to append as an appendix to all manuals.
-#latex_appendices = []
-
-# If false, no module index is generated.
-#latex_use_modindex = True
-
 html_theme = "nature"
 html_theme_path = ["_theme"]

+ 0 - 1
docs/slidesource/slide-example1-result.py

@@ -8,4 +8,3 @@ res = MyTask.apply_async(args=[8, 4],
                          countdown=5)
 res.get() # Is executed after 5 seconds.
 #32
-