瀏覽代碼

Use Py3.2's threading.TIMEOUT_MAX. Closes #796

Ask Solem 13 年之前
父節點
當前提交
4992a44d17
共有 3 個文件被更改,包括 11 次插入4 次删除
  1. 2 1
      celery/tests/utilities/test_datastructures.py
  2. 6 1
      celery/utils/threads.py
  3. 3 2
      celery/utils/timer2.py

+ 2 - 1
celery/tests/utilities/test_datastructures.py

@@ -10,6 +10,7 @@ from celery.datastructures import (
     ConfigurationView,
     ConfigurationView,
     DependencyGraph,
     DependencyGraph,
 )
 )
+from celery.utils.threads import TIMEOUT_MAX
 from celery.tests.utils import Case, WhateverIO
 from celery.tests.utils import Case, WhateverIO
 
 
 
 
@@ -222,7 +223,7 @@ class test_LRUCache(Case):
             def stop(self):
             def stop(self):
                 self._is_shutdown.set()
                 self._is_shutdown.set()
                 self._is_stopped.wait()
                 self._is_stopped.wait()
-                self.join(1e10)
+                self.join(TIMEOUT_MAX)
 
 
         burglar = Burglar(x)
         burglar = Burglar(x)
         burglar.start()
         burglar.start()

+ 6 - 1
celery/utils/threads.py

@@ -24,6 +24,11 @@ _Event = threading._Event
 active_count = (getattr(threading, 'active_count', None) or
 active_count = (getattr(threading, 'active_count', None) or
                 threading.activeCount)
                 threading.activeCount)
 
 
+try:
+    TIMEOUT_MAX = threading.TIMEOUT_MAX
+except AttributeError:
+    TIMEOUT_MAX = 1e10  # noqa
+
 
 
 class Event(_Event):
 class Event(_Event):
 
 
@@ -93,7 +98,7 @@ class bgThread(Thread):
         self._is_shutdown.set()
         self._is_shutdown.set()
         self._is_stopped.wait()
         self._is_stopped.wait()
         if self.is_alive():
         if self.is_alive():
-            self.join(1e100)
+            self.join(TIMEOUT_MAX)
 
 
 try:
 try:
     from greenlet import getcurrent as get_ident
     from greenlet import getcurrent as get_ident

+ 3 - 2
celery/utils/timer2.py

@@ -15,11 +15,12 @@ import os
 import sys
 import sys
 import threading
 import threading
 
 
+from datetime import datetime, timedelta
 from functools import wraps
 from functools import wraps
 from itertools import count
 from itertools import count
 from time import time, sleep, mktime
 from time import time, sleep, mktime
 
 
-from datetime import datetime, timedelta
+from celery.utils.threads import TIMEOUT_MAX
 from kombu.log import get_logger
 from kombu.log import get_logger
 
 
 VERSION = (1, 0, 0)
 VERSION = (1, 0, 0)
@@ -276,7 +277,7 @@ class Timer(threading.Thread):
         if self.running:
         if self.running:
             self._is_shutdown.set()
             self._is_shutdown.set()
             self._is_stopped.wait()
             self._is_stopped.wait()
-            self.join(1e10)
+            self.join(TIMEOUT_MAX)
             self.running = False
             self.running = False
 
 
     def ensure_started(self):
     def ensure_started(self):