Browse Source

Adds utils.reprcall

Ask Solem 14 years ago
parent
commit
b638635dcb
2 changed files with 14 additions and 8 deletions
  1. 3 5
      celery/task/sets.py
  2. 11 3
      celery/utils/__init__.py

+ 3 - 5
celery/task/sets.py

@@ -7,7 +7,7 @@ from kombu.utils import cached_property
 from celery import registry
 from celery.app import app_or_default
 from celery.datastructures import AttributeDict
-from celery.utils import gen_unique_id
+from celery.utils import gen_unique_id, reprcall
 from celery.utils.compat import UserList
 
 TASKSET_DEPRECATION_TEXT = """\
@@ -97,10 +97,8 @@ class subtask(AttributeDict):
         # and not stored in the dict itself.
         return (self.__class__, (dict(self), ), None)
 
-    def __repr__(self, kwformat=lambda i: "%s=%r" % i, sep=', '):
-        kw = self["kwargs"]
-        return "%s(%s%s%s)" % (self["task"], sep.join(map(repr, self["args"])),
-                kw and sep or "", sep.join(map(kwformat, kw.iteritems())))
+    def __repr__(self):
+        return reprcall(self["task"], self["args"], self["kwargs"])
 
     @cached_property
     def type(self):

+ 11 - 3
celery/utils/__init__.py

@@ -423,14 +423,22 @@ def cry():
             main_thread = t
 
     out = StringIO()
+    sep = "=" * 49 + "\n"
     for tid, frame in sys._current_frames().iteritems():
         thread = tmap.get(tid, main_thread)
         out.write("%s\n" % (thread.getName(), ))
-        out.write("=================================================\n")
+        out.write(sep)
         traceback.print_stack(frame, file=out)
-        out.write("=================================================\n")
+        out.write(sep)
         out.write("LOCAL VARIABLES\n")
-        out.write("=================================================\n")
+        out.write(sep)
         pprint(frame.f_locals, stream=out)
         out.write("\n\n")
     return out.getvalue()
+
+
+def reprcall(name, args=(), kwargs=(), sep=', ',
+        kwformat=lambda i: "%s=%r" % i):
+    return "%s(%s%s%s)" % (name, sep.join(map(repr, args)),
+                           kwargs and sep or "",
+                           sep.join(map(kwformat, kwargs.iteritems())))