[Answer]-Django app is blocked when calling linux ping

1👍

Use

cmd = "ping -c 1 %s -W 2" % host

-W is for timeout.

It is not a python issue. The command blocks

EDIT:
It works fine.
try this
Code:

import os
host="10.13.1.23"
def verify_host(host):
    cmd = "ping -c 1 -W 5 %s" % host
    if os.system(cmd):
        return False
    return True

print verify_host(host)

Output:

$python file.py
PING 10.13.1.23 (10.13.1.23) 56(84) bytes of data.

--- 10.13.1.23 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

False
👤duck

Leave a comment