|
@ -1,6 +1,7 @@ |
|
|
# axel.py |
|
|
# axel.py |
|
|
# |
|
|
# |
|
|
# Copyright (C) 2010 Adrian Cristea adrian dot cristea at gmail dotcom |
|
|
# Copyright (C) 2010 Adrian Cristea adrian dot cristea at gmail dotcom |
|
|
|
|
|
# Edits by Ruud Burger |
|
|
# |
|
|
# |
|
|
# Based on an idea by Peter Thatcher, found on |
|
|
# Based on an idea by Peter Thatcher, found on |
|
|
# http://www.valuedlessons.com/2008/04/events-in-python.html |
|
|
# http://www.valuedlessons.com/2008/04/events-in-python.html |
|
@ -11,12 +12,14 @@ |
|
|
# Source: http://pypi.python.org/pypi/axel |
|
|
# Source: http://pypi.python.org/pypi/axel |
|
|
# Docs: http://packages.python.org/axel |
|
|
# Docs: http://packages.python.org/axel |
|
|
|
|
|
|
|
|
from couchpotato.core.helpers.variable import natsortKey |
|
|
from Queue import Empty, Queue |
|
|
import Queue |
|
|
|
|
|
import hashlib |
|
|
import hashlib |
|
|
import sys |
|
|
import sys |
|
|
import threading |
|
|
import threading |
|
|
|
|
|
|
|
|
|
|
|
from couchpotato.core.helpers.variable import natsortKey |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Event(object): |
|
|
class Event(object): |
|
|
""" |
|
|
""" |
|
|
Event object inspired by C# events. Handlers can be registered and |
|
|
Event object inspired by C# events. Handlers can be registered and |
|
@ -140,7 +143,7 @@ class Event(object): |
|
|
|
|
|
|
|
|
def fire(self, *args, **kwargs): |
|
|
def fire(self, *args, **kwargs): |
|
|
""" Stores all registered handlers in a queue for processing """ |
|
|
""" Stores all registered handlers in a queue for processing """ |
|
|
self.queue = Queue.Queue() |
|
|
self.queue = Queue() |
|
|
result = {} |
|
|
result = {} |
|
|
|
|
|
|
|
|
if self.handlers: |
|
|
if self.handlers: |
|
@ -239,9 +242,9 @@ class Event(object): |
|
|
order_lock.release() |
|
|
order_lock.release() |
|
|
|
|
|
|
|
|
if self.queue.empty(): |
|
|
if self.queue.empty(): |
|
|
raise Queue.Empty |
|
|
raise Empty |
|
|
|
|
|
|
|
|
except Queue.Empty: |
|
|
except Empty: |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
def _extract(self, queue_item): |
|
|
def _extract(self, queue_item): |
|
|