If I catch the pymongo.errors.OperationFailure exception and print the error. It shows the following message, where host1:27018 is the killed primary.
write results unavailable from host1:27018 :: caused by :: Location11002: socket exception [CONNECT_ERROR] for host1:27018
If I let it fail, without catching exception.
Unexpected error: <class 'pymongo.errors.WriteError'> , for index 349999
Traceback (most recent call last):
File "loaddb.py", line 46, in <module>
collection.insert(batch)
File "/usr/local/lib/python3.5/dist-packages/pymongo/collection.py", line 2469, in insert
check_keys, manipulate, write_concern)
File "/usr/local/lib/python3.5/dist-packages/pymongo/collection.py", line 611, in _insert
_check_write_command_response(results)
File "/usr/local/lib/python3.5/dist-packages/pymongo/helpers.py", line 315, in _check_write_command_response
raise WriteError(error.get("errmsg"), error.get("code"), error)
pymongo.errors.WriteError: interrupted at shutdown