{"action":"created","issue":{"url":"https://api.github.com/repos/borgbackup/borg/issues/825","repository_url":"https://api.github.com/repos/borgbackup/borg","labels_url":"https://api.github.com/repos/borgbackup/borg/issues/825/labels{/name}","comments_url":"https://api.github.com/repos/borgbackup/borg/issues/825/comments","events_url":"https://api.github.com/repos/borgbackup/borg/issues/825/events","html_url":"https://github.com/borgbackup/borg/issues/825","id":145302183,"number":825,"title":"Borg doesn't respond to Ctrl-C as expected","user":{"login":"garethrees","id":282788,"avatar_url":"https://avatars.githubusercontent.com/u/282788?v=3","gravatar_id":"","url":"https://api.github.com/users/garethrees","html_url":"https://github.com/garethrees","followers_url":"https://api.github.com/users/garethrees/followers","following_url":"https://api.github.com/users/garethrees/following{/other_user}","gists_url":"https://api.github.com/users/garethrees/gists{/gist_id}","starred_url":"https://api.github.com/users/garethrees/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garethrees/subscriptions","organizations_url":"https://api.github.com/users/garethrees/orgs","repos_url":"https://api.github.com/users/garethrees/repos","events_url":"https://api.github.com/users/garethrees/events{/privacy}","received_events_url":"https://api.github.com/users/garethrees/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-04-01T22:38:56Z","updated_at":"2016-04-02T16:04:19Z","closed_at":null,"body":"I'm trying to write a script that pulls a few borg commands together to run some automated backups.\r\n\r\nI want to handle interrupts with a cleanup command in the script, but borg doesn't seem to handle the Ctrl-C signal as I'd expect.\r\n\r\nI've put together a simple Vagrant box and demo scripts to be able to reproduce the issue: https://github.com/garethrees/borg-trap-test\r\n\r\nThe box includes two scripts:\r\n\r\n- [`traptest`](https://github.com/garethrees/borg-trap-test/blob/master/Vagrantfile#L84-L104): A simple example of how I want to use `trap` and how it responds\r\n- [`borgtest`](https://github.com/garethrees/borg-trap-test/blob/master/Vagrantfile#L11-L81): A simplified example of my backup script\r\n\r\nI'll break up the output to explain what's happening at each stage, but you can see the full output here: https://github.com/garethrees/borg-trap-test/issues/1\r\n\r\n```sh\r\n# Run the sample script\r\nubuntu@ubuntu-xenial:~$ ./borgtest\r\n# Make a source and destination\r\nCreating source...\r\nCreating destination...\r\n\r\n# Ctrl-C immediately after the borg init\r\nInitializing borg repo...\r\n^CException ignored in: <bound method Repository.__del__ of <Repository /tmp/backups>>\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3/dist-packages/borg/repository.py\", line 67, in __del__\r\n    self.close()\r\n  File \"/usr/lib/python3/dist-packages/borg/repository.py\", line 155, in close\r\n    if self.lock:\r\nAttributeError: 'Repository' object has no attribute 'lock'\r\nKeyboard interrupt.\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3.5/socket.py\", line 662, in getfqdn\r\n    hostname, aliases, ipaddrs = gethostbyaddr(name)\r\nsocket.gaierror: [Errno -2] Name or service not known\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python3/dist-packages/borg/archiver.py\", line 1466, in main\r\n    exit_code = archiver.run(args)\r\n  File \"/usr/lib/python3/dist-packages/borg/archiver.py\", line 1420, in run\r\n    return args.func(args)\r\n  File \"/usr/lib/python3/dist-packages/borg/archiver.py\", line 92, in do_init\r\n    repository = self.open_repository(args, create=True, exclusive=True)\r\n  File \"/usr/lib/python3/dist-packages/borg/archiver.py\", line 67, in open_repository\r\n    repository = Repository(location.path, create=create, exclusive=exclusive, lock_wait=self.lock_wait, lock=lock)\r\n  File \"/usr/lib/python3/dist-packages/borg/repository.py\", line 57, in __init__\r\n    self._location = Location('file://%s' % self.path)\r\n  File \"/usr/lib/python3/dist-packages/borg/helpers.py\", line 706, in __init__\r\n    if not self.parse(self.orig):\r\n  File \"/usr/lib/python3/dist-packages/borg/helpers.py\", line 723, in parse\r\n    text = self.preformat_text(text)\r\n  File \"/usr/lib/python3/dist-packages/borg/helpers.py\", line 714, in preformat_text\r\n    'fqdn': socket.getfqdn(),\r\n  File \"/usr/lib/python3.5/socket.py\", line 662, in getfqdn\r\n    hostname, aliases, ipaddrs = gethostbyaddr(name)\r\nKeyboardInterrupt\r\n\r\nPlatform: Linux ubuntu-xenial 4.4.0-16-generic #32-Ubuntu SMP Thu Mar 24 22:38:01 UTC 2016 x86_64 x86_64\r\nLinux: Ubuntu 16.04 xenial  LibC: glibc 2.9\r\nBorg: 1.0.0  Python: CPython 3.5.1+\r\nPID: 9524  CWD: /home/ubuntu\r\nsys.argv: ['/usr/bin/borg', 'init', '--encryption=none', '/tmp/backups']\r\nSSH_ORIGINAL_COMMAND: None\r\n```\r\n\r\nI'm not sure why there's a Python backtrace, but in any case, I'd expect my `clean_up` function to be run now. It isn't:\r\n\r\n```sh\r\n# The script continues…\r\nCreating new backup...\r\nreading files cache\r\nprocessing files\r\n------------------------------------------------------------------------------\r\nArchive name: 4ad26226c097\r\nArchive fingerprint: f2787be4f6a00e28a15164812613b5d2a3296f46bf56cead122b6da344c67636\r\nTime (start): Fri, 2016-04-01 22:19:16\r\nTime (end):   Fri, 2016-04-01 22:19:16\r\nDuration: 0.04 seconds\r\nNumber of files: 1\r\n------------------------------------------------------------------------------\r\n                       Original size      Compressed size    Deduplicated size\r\nThis archive:                  492 B                498 B                498 B\r\nAll archives:                  984 B                996 B                996 B\r\n\r\n                       Unique chunks         Total chunks\r\nChunk index:                       4                    4\r\n------------------------------------------------------------------------------\r\nPruning old backups...\r\nChecking backups...\r\n```\r\n\r\nAnd then the \"normal\" cleanup is run:\r\n\r\n```sh\r\nUnmounting /tmp/backups\r\nUnmounting /tmp/source\r\n```\r\n\r\nI'd expect the output to look like this:\r\n\r\n```sh\r\nubuntu@ubuntu-xenial:~$ ./borgtest\r\nCreating source...\r\nCreating destination...\r\n# Ctrl-C immediately after the borg init\r\nInitializing borg repo...\r\n^CUnmounting /tmp/backups\r\nUnmounting /tmp/source\r\n```\r\n\r\nNot sure if this is something I'm doing wrong or an issue with borg, but given the simpler example without borg, it feels like it might be borg that's not behaving.\r\n\r\nThanks!"},"comment":{"url":"https://api.github.com/repos/borgbackup/borg/issues/comments/204744845","html_url":"https://github.com/borgbackup/borg/issues/825#issuecomment-204744845","issue_url":"https://api.github.com/repos/borgbackup/borg/issues/825","id":204744845,"user":{"login":"ThomasWaldmann","id":356103,"avatar_url":"https://avatars.githubusercontent.com/u/356103?v=3","gravatar_id":"","url":"https://api.github.com/users/ThomasWaldmann","html_url":"https://github.com/ThomasWaldmann","followers_url":"https://api.github.com/users/ThomasWaldmann/followers","following_url":"https://api.github.com/users/ThomasWaldmann/following{/other_user}","gists_url":"https://api.github.com/users/ThomasWaldmann/gists{/gist_id}","starred_url":"https://api.github.com/users/ThomasWaldmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThomasWaldmann/subscriptions","organizations_url":"https://api.github.com/users/ThomasWaldmann/orgs","repos_url":"https://api.github.com/users/ThomasWaldmann/repos","events_url":"https://api.github.com/users/ThomasWaldmann/events{/privacy}","received_events_url":"https://api.github.com/users/ThomasWaldmann/received_events","type":"User","site_admin":false},"created_at":"2016-04-02T16:04:19Z","updated_at":"2016-04-02T16:04:19Z","body":"Some of the errors you see might be because your host has troubles with its own hostname / its own IP address. Other than that @Ape is right, this might be already fixed in master branch, so please try to reproduce with current code."}}