You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

10 lines
1.1 KiB

  1. <div class="highlight"><pre><span></span><span class="c1"># Using Python 3 standard library:</span>
  2. <span class="kn">import</span> <span class="nn">socket</span>
  3. <span class="kn">import</span> <span class="nn">urllib.request</span>
  4. <span class="k">try</span><span class="p">:</span>
  5. <span class="n">urllib</span><span class="o">.</span><span class="n">request</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="s2">&quot;{{ ping_url }}&quot;</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mi">10</span><span class="p">)</span>
  6. <span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
  7. <span class="c1"># Log ping failure here...</span>
  8. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Ping failed: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">e</span><span class="p">)</span>
  9. </pre></div>