mirror of
https://github.com/moparisthebest/SickRage
synced 2024-11-11 03:45:01 -05:00
74f73bcc34
Fixed ctrl-c issues with new event queue system. Added a sleep timer to the NameParser class to help lower cpu usage spikes.
45 lines
1.0 KiB
Python
45 lines
1.0 KiB
Python
from threading import Thread
|
|
from Queue import Queue, Empty
|
|
from tornado.ioloop import IOLoop
|
|
|
|
class Event:
|
|
def __init__(self, type):
|
|
self._type = type
|
|
|
|
@property
|
|
def type(self):
|
|
return self._type
|
|
|
|
class Events(Thread):
|
|
def __init__(self, callback):
|
|
super(Events, self).__init__()
|
|
self.queue = Queue()
|
|
self.daemon = True
|
|
self.alive = True
|
|
self.callback = callback
|
|
self.name = "EVENT-QUEUE"
|
|
|
|
# auto-start
|
|
self.start()
|
|
|
|
def put(self, type):
|
|
self.queue.put_nowait(type)
|
|
|
|
def run(self):
|
|
while(self.alive):
|
|
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 Empty:
|
|
type = None
|
|
|
|
# System Events
|
|
class SystemEvent(Event):
|
|
RESTART = "RESTART"
|
|
SHUTDOWN = "SHUTDOWN" |