If I have walletnotify set in my conf and try to import a private key, it always fails with:
$ bitcoin-cli importprivkey $key
error: {"code":-1,"message":"boost::thread_resource_error: Resource temporarily unavailable"}
I was watching the debug log when this happens, and see the rescan is calling AddToWallet for ALL past transactions, not just for the new imported private key. And it's trying to run the walletnotify program for every transaction.
The only way I can get this to work is to first stop bitcoin, disable walletnotify, then restart bitcoin to perform the importprivkey, then stop and re-enable walletnotify and restart.