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
|
|
@ -18,7 +18,6 @@ logger = logging.getLogger(__name__)
|
|||
class Downloads(Thread):
|
||||
|
||||
def __init__(self):
|
||||
self._running = True
|
||||
Thread.__init__(self)
|
||||
self.daemon = True
|
||||
self.start()
|
||||
|
|
@ -36,9 +35,11 @@ class Downloads(Thread):
|
|||
for t in item.models.Transfer.query.filter(
|
||||
item.models.Transfer.added!=None,
|
||||
item.models.Transfer.progress<1).order_by(item.models.Transfer.added):
|
||||
if not self._running:
|
||||
if state.shutdown:
|
||||
return False
|
||||
for u in t.item.users:
|
||||
if state.shutdown:
|
||||
return False
|
||||
if state.nodes.is_online(u.id):
|
||||
logger.debug('DOWNLOAD %s %s', t.item, u)
|
||||
r = state.nodes.download(u.id, t.item)
|
||||
|
|
@ -47,14 +48,13 @@ class Downloads(Thread):
|
|||
|
||||
def run(self):
|
||||
self.wait(10)
|
||||
while self._running:
|
||||
while not state.shutdown:
|
||||
self.wait_online()
|
||||
with db.session():
|
||||
self.download_next()
|
||||
self.wait(10)
|
||||
|
||||
def join(self):
|
||||
self._running = False
|
||||
return Thread.join(self)
|
||||
|
||||
def wait_online(self):
|
||||
|
|
@ -63,7 +63,7 @@ class Downloads(Thread):
|
|||
|
||||
def wait(self, timeout):
|
||||
step = min(timeout, 1)
|
||||
while self._running and timeout > 0:
|
||||
while not state.shutdown and timeout > 0:
|
||||
time.sleep(step)
|
||||
timeout -= step
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue