Skip to content

Instantly share code, notes, and snippets.

View giampaolo's full-sized avatar

Giampaolo Rodola giampaolo

View GitHub Profile
@giampaolo
giampaolo / is_connection_err.py
Last active February 26, 2026 17:09
Check whether an exception is a connection error
"""
Recognize a connection error from an exception object.
Blog post:
https://gmpy.dev/blog/2023/recognize-connection-errors
Author: Giampaolo Rodola
License: MIT
"""
"""
People erroneously think that any function registered via atexit.register()
will be executed on interpreter exit.
This is not always true. For example, in case of SIGTERM:
import atexit, os, signal
@atexit.register
def cleanup():
print("on exit") # XXX this never gets printed