mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-11 05:33:37 +00:00
Merge pull request #1034 from JackDandy/feature/FixEvents
Fix Events shutdown (a manual start-up is required after updating to this fix).
This commit is contained in:
commit
8094a64e35
2 changed files with 20 additions and 13 deletions
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
[develop changelog]
|
[develop changelog]
|
||||||
|
|
||||||
|
* Fix Events shutdown (a manual start-up is required after updating to this fix)
|
||||||
|
|
||||||
|
|
||||||
### 0.13.9 (2018-01-02 15:45:00 UTC)
|
### 0.13.9 (2018-01-02 15:45:00 UTC)
|
||||||
|
|
||||||
|
|
|
@ -2,44 +2,49 @@ from lib.six import moves
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
|
||||||
class Event:
|
class Event:
|
||||||
def __init__(self, type):
|
def __init__(self, etype):
|
||||||
self._type = type
|
self._type = etype
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def type(self):
|
def type(self):
|
||||||
return self._type
|
return self._type
|
||||||
|
|
||||||
|
|
||||||
class Events(threading.Thread):
|
class Events(threading.Thread):
|
||||||
def __init__(self, callback):
|
def __init__(self, callback):
|
||||||
super(Events, self).__init__()
|
super(Events, self).__init__()
|
||||||
self.queue = moves.queue.Queue()
|
self.queue = moves.queue.Queue()
|
||||||
self.daemon = True
|
self.daemon = True
|
||||||
self.callback = callback
|
self.callback = callback
|
||||||
self.name = "EVENT-QUEUE"
|
self.name = 'EVENT-QUEUE'
|
||||||
self.stop = threading.Event()
|
self._stop = threading.Event()
|
||||||
|
|
||||||
def put(self, type):
|
def put(self, etype):
|
||||||
self.queue.put(type)
|
self.queue.put(etype)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self._stop.set()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
while (not self.stop.is_set()):
|
while not self._stop.is_set():
|
||||||
try:
|
try:
|
||||||
# get event type
|
# get event type
|
||||||
type = self.queue.get(True, 1)
|
etype = self.queue.get(True, 1)
|
||||||
|
|
||||||
# perform callback if we got a event type
|
# perform callback if we got a event type
|
||||||
self.callback(type)
|
self.callback(etype)
|
||||||
|
|
||||||
# event completed
|
# event completed
|
||||||
self.queue.task_done()
|
self.queue.task_done()
|
||||||
except moves.queue.Empty:
|
except moves.queue.Empty:
|
||||||
type = None
|
pass
|
||||||
|
|
||||||
# exiting thread
|
# exiting thread
|
||||||
self.stop.clear()
|
self._stop.clear()
|
||||||
|
|
||||||
# System Events
|
# System Events
|
||||||
class SystemEvent(Event):
|
class SystemEvent(Event):
|
||||||
RESTART = "RESTART"
|
RESTART = 'RESTART'
|
||||||
SHUTDOWN = "SHUTDOWN"
|
SHUTDOWN = 'SHUTDOWN'
|
||||||
|
|
Loading…
Reference in a new issue