return write_progress
def exit_signal_handler(sigcode, frame):
+ logging.getLogger('arvados.arv_put').error("Caught signal {}, exiting.".format(sigcode))
sys.exit(-sigcode)
def desired_project_uuid(api_client, project_uuid, num_retries):
if api_client is None:
api_client = arvados.api('v1', request_id=request_id)
+ # Install our signal handler for each code in CAUGHT_SIGNALS, and save
+ # the originals.
+ orig_signal_handlers = {sigcode: signal.signal(sigcode, exit_signal_handler)
+ for sigcode in CAUGHT_SIGNALS}
+
# Determine the name to use
if args.name:
if args.stream or args.raw:
"arv-put: %s" % str(error)]))
sys.exit(1)
- # Install our signal handler for each code in CAUGHT_SIGNALS, and save
- # the originals.
- orig_signal_handlers = {sigcode: signal.signal(sigcode, exit_signal_handler)
- for sigcode in CAUGHT_SIGNALS}
-
if not args.dry_run and not args.update_collection and args.resume and writer.bytes_written > 0:
logger.warning("\n".join([
"arv-put: Resuming previous upload from last checkpoint.",
import random
import re
import shutil
+import signal
import subprocess
import sys
import tempfile
self.assertIn('4a9c8b735dce4b5fa3acf221a0b13628+11',
pipe.stdout.read().decode())
+ def test_sigint_logs_request_id(self):
+ # Connect 'yes' command output to arv-put, wait for a second and
+ # send SIGINT to arv-put's process, then check if its output includes
+ # the X-Request-Id.
+ input_stream = subprocess.Popen(
+ 'yes', stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+ pipe = subprocess.Popen(
+ [sys.executable, arv_put.__file__, '--stream'],
+ stdin=input_stream.stdout, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT, env=self.ENVIRON)
+ time.sleep(1)
+ pipe.send_signal(signal.SIGINT)
+ deadline = time.time() + 5
+ while (pipe.poll() is None) and (time.time() < deadline):
+ time.sleep(.1)
+ returncode = pipe.poll()
+ input_stream.terminate()
+ if returncode is None:
+ pipe.terminate()
+ self.fail("arv-put did not exited within 5 seconds")
+ self.assertRegex(pipe.stdout.read().decode(), r'\(X-Request-Id: req-[a-z0-9]{20}\)')
+
def test_ArvPutSignedManifest(self):
# ArvPutSignedManifest runs "arv-put foo" and then attempts to get
# the newly created manifest from the API server, testing to confirm