fix shutdown

This commit is contained in:
j 2015-11-18 01:27:53 +01:00
parent 1405582cc2
commit 26da12dedd
5 changed files with 29 additions and 6 deletions

15
ctl
View file

@ -82,8 +82,21 @@ if [ "$1" == "debug" ]; then
fi
if [ "$1" == "stop" ]; then
remove_loginscript
test -e $PID && kill `cat $PID`
if [ -e $PID ]; then
_PID=`cat $PID`
kill $_PID
waited=0
while ps -p $_PID > /dev/null
do
sleep 1
waited=$(($waited+1))
if [ $waited -gt 10 ]; then
kill -9 $_PID
sleep 1
fi
done
test -e $PID && rm $PID
fi
exit $?
fi
if [ "$1" == "restart" ]; then

View file

@ -35,6 +35,8 @@ 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:
return False
for u in t.item.users:
if state.nodes.is_online(u.id):
logger.debug('DOWNLOAD %s %s', t.item, u)
@ -69,7 +71,7 @@ class ScrapeThread(Thread):
item.models.Scrape.added!=None,
).order_by(item.models.Scrape.added):
if not self._running:
return False
return True
logger.debug('scrape %s', s.item)
try:
s.item.scrape()

View file

@ -31,6 +31,8 @@ def remove_missing():
prefix = os.path.join(os.path.expanduser(prefs['libraryPath']), 'Books/')
if os.path.exists(prefix):
for f in File.query:
if not state.tasks.connected:
return
path = f.item.get_path()
if not os.path.exists(path):
dirty = True
@ -73,6 +75,8 @@ def run_scan():
books = []
for root, folders, files in os.walk(prefix):
for f in files:
if not state.tasks.connected:
return
#if f.startswith('._') or f == '.DS_Store':
if f.startswith('.'):
continue
@ -84,6 +88,8 @@ def run_scan():
position = 0
added = 0
for f in ox.sorted_strings(books):
if not state.tasks.connected:
return
position += 1
id = media.get_id(f)
file = File.get(id)
@ -96,6 +102,7 @@ def run_import(options=None):
options = options or {}
with db.session():
logger.debug('run_import')
prefs = settings.preferences
prefix = os.path.expanduser(options.get('path', prefs['importPath']))
if os.path.islink(prefix):
@ -128,6 +135,8 @@ def run_import(options=None):
count = 0
for root, folders, files in os.walk(prefix):
for f in files:
if not state.tasks.connected:
return
#if f.startswith('._') or f == '.DS_Store':
if f.startswith('.'):
continue

View file

@ -119,13 +119,13 @@ def run():
def shutdown():
if state.downloads:
state.downloads.join()
if state.tasks:
state.tasks.join()
if state.nodes:
state.nodes.join()
if state.scraping:
state.scraping.join()
http_server.stop()
if state.tasks:
state.tasks.join()
if PID and os.path.exists(PID):
os.unlink(PID)

View file

@ -45,7 +45,6 @@ class Tasks(Thread):
def join(self):
self.connected = False
self.q.put(None)
self.q.join()
return Thread.join(self)
def queue(self, action, data=None):