Revision a83e4de2

View differences:

sdk/python/arvados/commands/put.py
391 391
        self._upload_started = False
392 392
        self.logger = logger
393 393
        self.dry_run = dry_run
394
        self._checkpoint_before_quit = True
394 395

  
395 396
        if not self.use_cache and self.resume:
396 397
            raise ArvPutArgumentConflict('resume cannot be True when use_cache is False')
......
447 448
            # Actual file upload
448 449
            self._upload_started = True # Used by the update thread to start checkpointing
449 450
            self._upload_files()
451
        except KeyboardInterrupt:
452
            self.logger.warning("User interrupt request, cleaning up before exiting.")
453
            self._checkpoint_before_quit = False
454
            raise
450 455
        finally:
451 456
            if not self.dry_run:
452 457
                # Stop the thread before doing anything else
453 458
                self._stop_checkpointer.set()
454 459
                self._checkpointer.join()
455
                try:
460
                if self._checkpoint_before_quit:
456 461
                    # Commit all pending blocks & one last _update()
457 462
                    self._local_collection.manifest_text()
458 463
                    self._update(final=True)
459 464
                    if save_collection:
460 465
                        self.save_collection()
461
                except AttributeError:
462
                    # Exception caught in inconsistent state, finish as is.
463
                    self.logger.warning("Couldn't save last checkpoint while exiting.")
464 466
            if self.use_cache:
465 467
                self._cache_file.close()
466 468

  
sdk/python/tests/test_arv_put.py
347 347
    # Test for bug #11002
348 348
    def test_graceful_exit_while_repacking_small_blocks(self):
349 349
        def wrapped_commit(*args, **kwargs):
350
            raise SystemExit("Simulated error")
350
            raise KeyboardInterrupt("Simulated error")
351 351

  
352 352
        with mock.patch('arvados.arvfile._BlockManager.commit_bufferblock',
353 353
                        autospec=True) as mocked_commit:
......
359 359
            writer = arv_put.ArvPutUploadJob([self.small_files_dir],
360 360
                                             replication_desired=1)
361 361
            try:
362
                with self.assertRaises(SystemExit):
362
                with self.assertRaises(KeyboardInterrupt):
363 363
                    writer.start(save_collection=False)
364 364
            except AttributeError:
365 365
                self.fail("arv-put command is trying to use a corrupted BlockManager. See https://dev.arvados.org/issues/11002")

Also available in: Unified diff