Cannot solve GPG error
This looks like the following bug to me.
How to Fix
From a user who fixed it in the bug report:
The solution that worked for me was emptying /etc/apt/trusted.gpg.d, running apt-get update, and then manually adding every key it blocked on to the main /etc/apt/trusted.gpg keyring with apt-key adv as described above.
So, in your case, you should do the following (disclaimer: could not test it ):
sudo mv /etc/apt/trusted.gpg.d/ /etc/apt/trusted.gpg.d.backup
sudo mkdir /etc/apt/trusted.gpg.d
sudo chmod 755 /etc/apt/trusted.gpg.d
Then, for each key you need:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5
where you replace the hash with your needed key's hash. As Ionică Bizău noted, multiple keys can be added, separated with a space.
Why it appeared
Apparently, gpg can only handle a limited number of keyrings, and your installation required more. Possibly, this is caused by having many alternative packet sources.
Again, from the bug report:
I asked about the "resource limit" message on the gnupg-users mailing list...
Based on Werner Koch's (the dev) answer...
...the secure apt related programs might be making gpg use more than the maximum number of keyrings that it can handle