Best way to check if there is internet?

Barry barry at barrys-emacs.org
Tue Feb 22 16:03:49 EST 2022



> On 22 Feb 2022, at 17:44, Abdur-Rahmaan Janhangeer <arj.python at gmail.com> wrote:
> 
> Well, nice perspective.
> 
> It's a valid consideration, sound theory
> but poor practicality according to me.
> 
> It you view it like this then between the moment
> we press run or enter key on the terminal,
> our Python interpreter might get deleted.

This is under your control usually so you do not need to check for python to be installed.
> 
> We never know, it can happen.
> 
> Though it's nice to go in and catch exceptions,
> if you have a long operation upcoming it might be nice
> to see if your key element is present.

You might check for enough disk space before starting to ensure that you can write the results, again this is usually under your control.

But you do not control the internet as an end user.
As it is not under your control you have to code to survive its failure modes.
For example email delivery is retried until the MTA gives up or succeeds.

> 
> Much like checking if goal posts are present before
> starting a football game. You can of course start
> the match, pass the ball around and when shooting
> you stop the match as you realise that the goal posts
> are not around.

Check before you start. But you are going to notice people attempting to take goal posts away while you play.

> Checking by exceptions is what the snippet
> i shared does. But we check for the ability to do it
> before we start.
> 
> Of course, it can change in the seconds that follow. But it's too much pure
> logic at work.

Since you have to deal with things that you do not control changing after you check what is the point in checking? You have to write the code to recover anyway.

Barry

> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list