Browse Source

Events now emits warning if the broken yajl json libray is used

Ask Solem 11 years ago
parent
commit
8c42df80c5
1 changed files with 15 additions and 0 deletions
  1. 15 0
      celery/events/__init__.py

+ 15 - 0
celery/events/__init__.py

@@ -14,6 +14,7 @@ import os
 import time
 import socket
 import threading
+import warnings
 
 from collections import deque
 from contextlib import contextmanager
@@ -36,6 +37,14 @@ event_exchange = Exchange('celeryev', type='topic')
 
 _TZGETTER = itemgetter('utcoffset', 'timestamp')
 
+W_YAJL = """
+anyjson is currently using the yajl library.
+This json implementation is broken, it severely truncates floats
+so timestamps will not work.
+
+Please uninstall yajl or force anyjson to use a different library.
+"""
+
 
 def get_exchange(conn):
     ex = copy(event_exchange)
@@ -139,6 +148,12 @@ class EventDispatcher(object):
             self.enable()
         self.headers = {'hostname': self.hostname}
         self.pid = os.getpid()
+        self.warn_if_yajl()
+
+    def warn_if_yajl(self):
+        import anyjson
+        if anyjson.implementation.name == 'yajl':
+            warnings.warn(UserWarning(W_YAJL))
 
     def __enter__(self):
         return self