Added the handling of IOError and select errors in the generation of keys.