First of all:
What you describe as your desired answer is what you actually call: I also don't want to create a script that constantl polls. Inotify also is used in a constant loop to "listen" to changes in the current state. In other words: the other option you assume to exist does not exist without some kind of a loop.
I also think your image of a loop is too heavy. On every system, in every application there are numerous loops active to wait for triggers. It should have no noticable effect on your resources.
The "anatomy" of such a take-action-on-event mechanism is basically:
in a while loop:
check the current status;
if a is True:
take action A
if a is False:
wait a few seconds
In a bash script
Integrating this script (to check your connection) in a while loop (with a few minor changes) should do what you describe: re-establish your connection and send a notification.
wget -q --tries=10 --timeout=20 --spider http://google.com
if [[ $? -eq 0 ]]; then
rfkill block wifi
rfkill unblock wifi
notify-send "connection re-established"
In a python script
check() returns True or False. If True (connection is up), nothing happens. If False, your
rfkill block wifi /
rfkill ublock wifi is executed.
host = socket.gethostbyname("www.google.com")
s = socket.create_connection((host, 80), 2)
if check() == True:
subprocess.call(["/bin/bash", "-c", "rfkill", "block", "wifi"])
subprocess.call(["/bin/bash", "-c", "rfkill", "unblock", "wifi"])
subprocess.Popen(["/bin/bash", "-c", "notify-send 'conncection re-established'"])