Commit b78ee581 authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Make download canceling more responsive

This does not make download canceling faster, if anything, it makes it slower
but probably more gracefull for end users. Instead of just waiting the threads
to finish, users now see messages that descibe the attempts made by kamaki to
cancel them. Each cancelation gets a timeout of 0.5 seconds, so that users
will not wait too long (although they might wait more overall)

Bug #3457
parent 50165863
......@@ -1312,16 +1312,17 @@ class store_download(_store_container_command):
if_modified_since=self['if_modified_since'],
if_unmodified_since=self['if_unmodified_since'])
except KeyboardInterrupt:
from threading import enumerate as activethreads
stdout.write('\nFinishing active threads ')
for thread in activethreads():
stdout.flush()
try:
thread.join()
stdout.write('.')
except RuntimeError:
continue
print('\ndownload canceled by user')
from threading import activeCount, enumerate as activethreads
while activeCount() > 1:
stdout.write('\nTry stop %s threads: ' % (activeCount() - 1))
for thread in activethreads():
stdout.flush()
try:
thread.join(0.5)
stdout.write('*')
except RuntimeError:
continue
print('\nDownload canceled by user')
if local_path is not None:
print('to resume, re-run with --resume')
except Exception:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment