Make download canceling more responsive
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 11 Apr 2013 13:55:45 +0000 (16:55 +0300)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Thu, 11 Apr 2013 13:55:45 +0000 (16:55 +0300)
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

kamaki/cli/commands/pithos_cli.py

index cbb4e23..cb1b352 100644 (file)
@@ -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: