Removed unused utilities
Change-Id: Ifa3e7b820d594303c6c02eae12f55bce2bd1dacc
This commit is contained in:
		| @@ -25,22 +25,6 @@ KWARGS_KEY = '__kwargs__' | |||||||
| ORDER_KEY = '__order__' | ORDER_KEY = '__order__' | ||||||
|  |  | ||||||
|  |  | ||||||
| def close_all(*args): |  | ||||||
|     for a in args: |  | ||||||
|         if not a: |  | ||||||
|             continue |  | ||||||
|         a.close() |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def null_functor(*args, **kwargs):  # pylint: disable=W0613 |  | ||||||
|     return None |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def drain(lst): |  | ||||||
|     while len(lst): |  | ||||||
|         lst.pop() |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def make_reverting_task(token, blowup=False): | def make_reverting_task(token, blowup=False): | ||||||
|  |  | ||||||
|     def do_revert(context, *args, **kwargs): |     def do_revert(context, *args, **kwargs): | ||||||
|   | |||||||
| @@ -20,7 +20,6 @@ import logging | |||||||
| import multiprocessing | import multiprocessing | ||||||
| import six | import six | ||||||
| import threading | import threading | ||||||
| import time |  | ||||||
| import types | import types | ||||||
|  |  | ||||||
| from taskflow.utils import lock_utils | from taskflow.utils import lock_utils | ||||||
| @@ -28,26 +27,6 @@ from taskflow.utils import lock_utils | |||||||
| LOG = logging.getLogger(__name__) | LOG = logging.getLogger(__name__) | ||||||
|  |  | ||||||
|  |  | ||||||
| def await(check_functor, timeout=None): |  | ||||||
|     """Spin-loops + sleeps awaiting for a given functor to return true.""" |  | ||||||
|     if timeout is not None: |  | ||||||
|         end_time = time.time() + max(0, timeout) |  | ||||||
|     else: |  | ||||||
|         end_time = None |  | ||||||
|     # Use the same/similar scheme that the python condition class uses. |  | ||||||
|     delay = 0.0005 |  | ||||||
|     while not check_functor(): |  | ||||||
|         time.sleep(delay) |  | ||||||
|         if end_time is not None: |  | ||||||
|             remaining = end_time - time.time() |  | ||||||
|             if remaining <= 0: |  | ||||||
|                 return False |  | ||||||
|             delay = min(delay * 2, remaining, 0.05) |  | ||||||
|         else: |  | ||||||
|             delay = min(delay * 2, 0.05) |  | ||||||
|     return True |  | ||||||
|  |  | ||||||
|  |  | ||||||
| def get_optimal_thread_count(): | def get_optimal_thread_count(): | ||||||
|     """Try to guess optimal thread count for current system.""" |     """Try to guess optimal thread count for current system.""" | ||||||
|     try: |     try: | ||||||
| @@ -59,42 +38,6 @@ def get_optimal_thread_count(): | |||||||
|         return 2 |         return 2 | ||||||
|  |  | ||||||
|  |  | ||||||
| class CountDownLatch(object): |  | ||||||
|     """Similar in concept to the java count down latch.""" |  | ||||||
|  |  | ||||||
|     def __init__(self, count=0): |  | ||||||
|         self.count = count |  | ||||||
|         self.lock = threading.Condition() |  | ||||||
|  |  | ||||||
|     def countDown(self): |  | ||||||
|         with self.lock: |  | ||||||
|             self.count -= 1 |  | ||||||
|             if self.count <= 0: |  | ||||||
|                 self.lock.notifyAll() |  | ||||||
|  |  | ||||||
|     def await(self, timeout=None): |  | ||||||
|         end_time = None |  | ||||||
|         if timeout is not None: |  | ||||||
|             timeout = max(0, timeout) |  | ||||||
|             end_time = time.time() + timeout |  | ||||||
|         time_up = False |  | ||||||
|         with self.lock: |  | ||||||
|             while True: |  | ||||||
|                 # Stop waiting on these 2 conditions. |  | ||||||
|                 if time_up or self.count <= 0: |  | ||||||
|                     break |  | ||||||
|                 # Was this a spurious wakeup or did we really end?? |  | ||||||
|                 self.lock.wait(timeout=timeout) |  | ||||||
|                 if end_time is not None: |  | ||||||
|                     if time.time() >= end_time: |  | ||||||
|                         time_up = True |  | ||||||
|                     else: |  | ||||||
|                         # Reduce the timeout so that we don't wait extra time |  | ||||||
|                         # over what we initially were requested to. |  | ||||||
|                         timeout = end_time - time.time() |  | ||||||
|             return self.count <= 0 |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class ThreadSafeMeta(type): | class ThreadSafeMeta(type): | ||||||
|     """Metaclass that adds locking to all pubic methods of a class""" |     """Metaclass that adds locking to all pubic methods of a class""" | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Ivan A. Melnikov
					Ivan A. Melnikov