use one variable to track app shutdown state
This commit is contained in:
parent
0cc3a4523e
commit
567952d91d
7 changed files with 35 additions and 44 deletions
|
|
@ -5,6 +5,7 @@ from queue import Queue
|
|||
from threading import Thread
|
||||
|
||||
from websocket import trigger_event
|
||||
import state
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -13,7 +14,6 @@ class Tasks(Thread):
|
|||
|
||||
def __init__(self):
|
||||
self.q = Queue()
|
||||
self.connected = True
|
||||
Thread.__init__(self)
|
||||
self.daemon = True
|
||||
self.start()
|
||||
|
|
@ -23,9 +23,9 @@ class Tasks(Thread):
|
|||
import item.scan
|
||||
from item.models import sync_metadata, get_preview
|
||||
from user.models import export_list, update_user_peering
|
||||
while self.connected:
|
||||
while not state.shutdown:
|
||||
m = self.q.get()
|
||||
if m and self.connected:
|
||||
if m and not state.shutdown:
|
||||
try:
|
||||
action, data = m
|
||||
logger.debug('%s start', action)
|
||||
|
|
@ -55,12 +55,11 @@ class Tasks(Thread):
|
|||
self.q.task_done()
|
||||
|
||||
def join(self):
|
||||
self.connected = False
|
||||
self.q.put(None)
|
||||
return Thread.join(self)
|
||||
|
||||
def queue(self, action, data=None):
|
||||
if self.connected:
|
||||
if not state.shutdown:
|
||||
logger.debug('%s queued', action)
|
||||
self.q.put((action, data))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue