1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-08-13 16:53:54 -04:00
SickRage/sickbeard/event_queue.py
echel0n 74f73bcc34 New event queue system in place, currently handles shutdown and restart calls.
Fixed ctrl-c issues with new event queue system.
Added a sleep timer to the NameParser class to help lower cpu usage spikes.
2014-07-08 15:26:26 -07:00

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"