Call atexit hook after all requests are done, or immediately if there are no requests

Addresses #140.