mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-05 02:43:37 +00:00
45 lines
No EOL
1 KiB
Python
45 lines
No EOL
1 KiB
Python
from lib.six import moves
|
|
|
|
import threading
|
|
|
|
class Event:
|
|
def __init__(self, type):
|
|
self._type = type
|
|
|
|
@property
|
|
def type(self):
|
|
return self._type
|
|
|
|
class Events(threading.Thread):
|
|
def __init__(self, callback):
|
|
super(Events, self).__init__()
|
|
self.queue = moves.queue.Queue()
|
|
self.daemon = True
|
|
self.callback = callback
|
|
self.name = "EVENT-QUEUE"
|
|
self.stop = threading.Event()
|
|
|
|
def put(self, type):
|
|
self.queue.put(type)
|
|
|
|
def run(self):
|
|
while (not self.stop.is_set()):
|
|
try:
|
|
# get event type
|
|
type = self.queue.get(True, 1)
|
|
|
|
# perform callback if we got a event type
|
|
self.callback(type)
|
|
|
|
# event completed
|
|
self.queue.task_done()
|
|
except moves.queue.Empty:
|
|
type = None
|
|
|
|
# exiting thread
|
|
self.stop.clear()
|
|
|
|
# System Events
|
|
class SystemEvent(Event):
|
|
RESTART = "RESTART"
|
|
SHUTDOWN = "SHUTDOWN" |