Axel python 2.5 fix
This commit is contained in:
@@ -10,4 +10,4 @@ from .axel import *
|
|||||||
__all__ = sorted(name for name, obj in locals().items()
|
__all__ = sorted(name for name, obj in locals().items()
|
||||||
if not (name.startswith('_') or inspect.ismodule(obj)))
|
if not (name.startswith('_') or inspect.ismodule(obj)))
|
||||||
__all__.append('axel')
|
__all__.append('axel')
|
||||||
del inspect
|
del inspec
|
||||||
@@ -52,8 +52,8 @@ class Event(object):
|
|||||||
>> None
|
>> None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, sender=None, asynch=False, exc_info=False,
|
def __init__(self, sender = None, asynch = False, exc_info = False,
|
||||||
lock=None, threads=3, traceback=False):
|
lock = None, threads = 3, traceback = False):
|
||||||
""" Creates an event
|
""" Creates an event
|
||||||
|
|
||||||
asynch
|
asynch
|
||||||
@@ -139,8 +139,8 @@ class Event(object):
|
|||||||
max_threads = self._threads()
|
max_threads = self._threads()
|
||||||
|
|
||||||
for i in range(max_threads):
|
for i in range(max_threads):
|
||||||
t = threading.Thread(target=self._execute,
|
t = threading.Thread(target = self._execute,
|
||||||
args=args, kwargs=kwargs)
|
args = args, kwargs = kwargs)
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ class Event(object):
|
|||||||
if not self.asynchronous:
|
if not self.asynchronous:
|
||||||
self.result.append(tuple(r))
|
self.result.append(tuple(r))
|
||||||
|
|
||||||
except Exception as err:
|
except Exception:
|
||||||
if not self.asynchronous:
|
if not self.asynchronous:
|
||||||
self.result.append((False, self._error(sys.exc_info()),
|
self.result.append((False, self._error(sys.exc_info()),
|
||||||
handler))
|
handler))
|
||||||
@@ -190,6 +190,9 @@ class Event(object):
|
|||||||
if not self.asynchronous:
|
if not self.asynchronous:
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
|
|
||||||
|
if self.queue.empty():
|
||||||
|
raise Queue.Empty
|
||||||
|
|
||||||
except Queue.Empty:
|
except Queue.Empty:
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -268,9 +271,10 @@ class Event(object):
|
|||||||
finally:
|
finally:
|
||||||
lock.release()
|
lock.release()
|
||||||
|
|
||||||
|
|
||||||
def _timeout(self, timeout, handler, *args, **kwargs):
|
def _timeout(self, timeout, handler, *args, **kwargs):
|
||||||
""" Controls the time allocated for the execution of a method """
|
""" Controls the time allocated for the execution of a method """
|
||||||
t = spawn_thread(target=handler, args=args, kwargs=kwargs)
|
t = spawn_thread(target = handler, args = args, kwargs = kwargs)
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
t.join(timeout)
|
t.join(timeout)
|
||||||
@@ -303,12 +307,12 @@ class Event(object):
|
|||||||
__iadd__ = handle
|
__iadd__ = handle
|
||||||
__isub__ = unhandle
|
__isub__ = unhandle
|
||||||
__call__ = fire
|
__call__ = fire
|
||||||
__len__ = count
|
__len__ = count
|
||||||
|
|
||||||
class spawn_thread(threading.Thread):
|
class spawn_thread(threading.Thread):
|
||||||
""" Spawns a new thread and returns the execution result """
|
""" Spawns a new thread and returns the execution result """
|
||||||
|
|
||||||
def __init__(self, target, args=(), kwargs={}, default=None):
|
def __init__(self, target, args = (), kwargs = {}, default = None):
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
self._target = target
|
self._target = target
|
||||||
self._args = args
|
self._args = args
|
||||||
Reference in New Issue
Block a user