Commits

gill...@gmail.com  committed bfd5dd6

Code is python3 compatible.

  • Participants
  • Parent commits bfc0360

Comments (0)

Files changed (3)

File asyncthreads/reactor.py

 __email__ = "gillis.andrewj@gmail.com"
 
 import threading
-import Queue
 import traceback
 import heapq
 import time
+from collections import Callable
+try:
+    import queue
+except ImportError:
+    import Queue as queue
+
 import threadpool
 
 
 
         """
         threading.Thread.__init__(self, None, None, None)
-        self._call_queue = Queue.Queue()
+        self._call_queue = queue.Queue()
         self.idle_wake_sec = None
         if thread_pool_size:
             self._thread_pool = threadpool.ThreadPool(thread_pool_size,
 
         """
         assert(self.is_alive()), 'reactor is not started'
-        assert(callable(func)), 'function is not callable'
+        assert(isinstance(func, Callable)), 'function is not callable'
         assert(callback is None or
-               callable(callback)),'callback is not callable'
+               isinstance(callback, Callable)),'callback is not callable'
         result = Result()
         self._call_queue.put((func, args, result, callback))
         return result
 
         """
         assert(self.is_alive()), 'reactor is not started'
-        assert(callable(func)), 'function is not callable'
+        assert(isinstance(func, Callable)), 'function is not callable'
         assert(callback is None or
-               callable(callback)), 'callback is not callable'
+               isinstance(callback, Callable)), 'callback is not callable'
         if time_until_call:
             action_time = time.time() + time_until_call
         else:
 
         """
         assert(self.is_alive()), 'reactor is not started'
-        assert(callable(func)), 'function is not callable'
+        assert(isinstance(func, Callable)), 'function is not callable'
         assert(callback is None or
-               callable(callback)), 'callback is not callable'
+               isinstance(callback, Callable)), 'callback is not callable'
         result = Result()
         if self._thread_pool:
             self._thread_pool.queue_task(self._thread_wrapper,
 
         """
         assert(self.is_alive()), 'reactor is not started'
-        assert(callable(func)), 'function is not callable'
+        assert(isinstance(func, Callable)), 'function is not callable'
         assert(callback is None or
-               callable(callback)), 'callback is not callable'
+               isinstance(callback, Callable)), 'callback is not callable'
         if time_until_call:
             action_time = time.time() + time_until_call
         else:
                 else:
                     self._thread_wrapper(func, args, result, callback)
 
-            except Queue.Empty:
+            except queue.Empty:
                 # Woke up because it is time do next scheduled task.
                 #print '===> woke up to do next scheduled task'
                 self._process_scheduled_queue()
                 continue
 
             except Exception:
-                print 'ERROR:', traceback.format_exc()
+                print('ERROR: '+str(traceback.format_exc()))
 
         return True
 

File asyncthreads/threadpool.py

 __email__ = "gillis.andrewj@gmail.com"
 
 import threading
-import Queue
 import time
+from collections import Callable
+try:
+    import queue
+except ImportError:
+    import Queue as queue
 
 
 class ThreadPool(object):
 
         self.__shutting_down = False
         self.__threads = 0
-        self.__task_queue = Queue.Queue(queue_size)
+        self.__task_queue = queue.Queue(queue_size)
         self.__resize_lock = threading.Condition(threading.Lock())
 
         self.resize_pool(pool_size)
         Insert a task function into the queue.
 
         """
-        assert(callable(function)), 'function is not callable'
+        assert(isinstance(function, Callable)), 'function is not callable'
         assert(callback is None or
-               callable(callback)), 'callback is not callable'
+               isinstance(callback, Callable)), 'callback is not callable'
 
         if not self.__shutting_down:
             self.__task_queue.put((function, args, callback), False)
             try:
                 self.__task_queue.get(False)
                 self.__task_queue.task_done()
-            except Queue.Empty:
+            except queue.Empty:
                 break
 
         self.resize_pool(0)
                 if callback is not None:
                     callback(ret)
             except Exception as e:
-                print 'ThreadPool task raised exception:', str(e)
+                print('ThreadPool task raised exception: '+str(e))
 
             task_queue.task_done()
 
 def main():
     setup(
         name='asyncthreads',
-        version= '1.2.0',
+        version= '1.2.1',
         author='Andrew Gillis',
         author_email='gillis.andrewj@gmail.com',
         url='http://bitbucket.org/agillis/asyncthreads',