Python Forum
How to run parallel command (same command -ping)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run parallel command (same command -ping)
#1
Hello ,
I have a code that read data from DB and return a list of IP (around 600 every query )
now I wrote a code that check if the device is online
but he check one by one , and it's about 4 second each so
600 can take ~ 2400 seconds ~ 40 min .....
is there any way to make him run 10 pings every check?
so it will take only ~ 4 min to check them all?

this is what I have now that is working :

def CheckOnLine(hostname):
    DeviceTTl = Getttl(hostname)
    if 200 > DeviceTTl > 0:
        print(hostname, "  TTL -  ", DeviceTTl, '  is up!')
        time.sleep(2)
        return True
    elif DeviceTTl == 250:
        print(hostname + " problem in Device 250")
        return False
    else:
        print(hostname, '  OFFLINE!')
        return False


def Getttl(ip):
    try:
        result = os.popen("ping -n 1 " + ip).read()
    except Exception as e:
        print(e)
        return -1
    else:
        n = result.find("TTL=")
        if n > 0:
            ttl = result[n + 4:]
            print(ttl)
            n = ttl.find("\n")
            if n > 0:
                print(ttl[:n])
                return int(ttl[:n])
    return -1
what I need to add?

Thanks ,
Reply
#2
A computer only executes a command one after the other. However, you might be able to speed up the proccess.
Reply
#3
https://superuser.com/questions/1586246/...ery-500-ms
Reply
#4
Asyncio might be your best bet:

https://docs.python.org/3/library/asyncio.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to pass a mongdb command to a module and execute it. cspower 0 276 Feb-03-2024, 09:54 PM
Last Post: cspower
  problem with print command in super() akbarza 5 507 Feb-01-2024, 12:25 PM
Last Post: deanhystad
  Is possible to run the python command to call python script on linux? cuten222 6 634 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  Basic Coding Question: Exit Program Command? RockBlok 3 504 Nov-19-2023, 06:31 PM
Last Post: deanhystad
  problem in using input command akbarza 4 1,000 Oct-19-2023, 03:27 PM
Last Post: popejose
  About command 'joblib.load' middlestudent 4 771 Sep-25-2023, 05:56 AM
Last Post: middlestudent
  Failure to run source command middlestudent 2 658 Sep-22-2023, 01:21 PM
Last Post: buran
  python command interface cwc2 5 1,125 Sep-20-2023, 05:19 AM
Last Post: Larz60+
  Formatting outputs created with .join command klairel 2 594 Aug-23-2023, 08:52 AM
Last Post: perfringo
  Need some guidance on a script to ping a list of ip's cubangt 11 1,691 Aug-10-2023, 02:39 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020