473,467 Members | 1,446 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

collecting ping replies using threads

32 New Member
Hi,

I would like to know why my string below(in bold) does provide only 1 result but should provide more result from a ping due that I put several IPs from a list to be ping ? ( this string filters the (% loss) from a ping command).

Expand|Select|Wrap|Line Numbers
  1.  
  2. class testit(Thread):
  3.    def __init__ (self,ip):
  4.       Thread.__init__(self)
  5.       self.ip = ip
  6.       self.status = -1
  7.    def run(self):
  8.       pingaling = os.popen("ping "+self.ip+" -n 10 ","r")
  9.  
  10. # This code is what each parallel thread does
  11. # the 'run' method is triggered when 'start' is called
  12.       while 1:
  13.          line = pingaling.read()
  14.          startopenbracket = line.find("(")   #<-----??????????????
  15.          startloss = line.find("loss")
  16.          print line[startopenbracket+1:startloss]         
  17.          if not line: break
  18.  
  19.  
Sep 18 '07 #1
3 2086
bartonc
6,596 Recognized Expert Expert
It's probably
Expand|Select|Wrap|Line Numbers
  1. if not line: break
Which will be true when read() returns and empty result. Your code will execute many times before read() will return the next good result (I think).
Sep 18 '07 #2
Charlie of Bolton
32 New Member
Hi,

Any suggestion on how on to modified this code : ( if not line: break )
to provided me all the IPs stats displayed on the Python Idle ?

Tks
Sep 19 '07 #3
bartonc
6,596 Recognized Expert Expert
Hi,

Any suggestion on how on to modified this code : ( if not line: break )
to provided me all the IPs stats displayed on the Python Idle ?

Tks
For threads, it's best to let them run in their loops until the main thread tells them to stop. Here's a quick example that I whipped up recently:
Expand|Select|Wrap|Line Numbers
  1. import time
  2. import threading
  3.  
  4. def FuncToRunAsThread(event):
  5.     print "started at %f" %time.time()
  6.     while not event.isSet():
  7.         pass  #do some work until the main thread sets the event
  8.     print "stopped at %f" %time.time()
  9.  
  10. if __name__ == "__main__":
  11.     thrdHandshake = threading.Event()
  12.     workerThread = threading.Thread(target=FuncToRunAsThread, args=(thrdHandshake,))
  13.     workerThread.start()
  14.     print workerThread.isAlive()
  15.     time.sleep(5)
  16.     thrdHandshake.set()  # Set the handshake flag that will terminate the thread
  17.     workerThread.join()  # wait here until the thread is actually terminated
  18.     print workerThread.isAlive()  # without the previous line, isAlive() will usually? be true
  19.     print "main thread terminated at %f" %time.time()
Sep 19 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ed | last post by:
I've attached some VB.NET code I've hacked together (some taken from MS examples & newsgroup postings) that will perform a ping or IcmpSendEcho using the icmp.dll (see this for more info:...
0
by: Adam Wayne | last post by:
I am trying to write a ping application that uses multiple threads to ping numerous hosts. I have copied the code from KB 828993 ( http://support.microsoft.com/default.aspx?scid=kb;EN-US;828993 )....
0
by: Antal Rutz | last post by:
Hi all, I'd like to collect snmp data from varoius network devices parallel. First I tried with my own threadpool class then I gave a try to Christopher Arndt's threadpool.py...
2
by: Ryan | last post by:
I want to ping every IP on a subnet (255 IP's) and display in a table what IP's are active. I'm currently using a For loop but this takes forever because it pauses to test each Ping. So my guess...
1
by: Krish | last post by:
All, I have an offline application that works online for some data syncronization. For data syncronization I access a webservice. I want to show whether my application is online or not by checking...
5
by: Michael M. | last post by:
I have the following code (listed at bottom of post) that pings a small range of IP address to see which ones are alive. To speed things up a little I am trying to use more than one thread,...
3
by: amaccormack | last post by:
I wrote a quick script to check the "up-ness" of a list of machines, and timeout after 1 second. However, with a lot of timeouts, the script takes a logn time, so I thought to parallelise it....
6
by: Dave Marden | last post by:
I currently use this routine in vbscript to ping computers and get the status of ping to determine whether to try to backup a machine, I am trying to change it to work with vb2003.net I am...
5
by: Mrown | last post by:
Hi, I was wondering if there was a ping implementation written in Python. I'd rather using a Python module that implements ping in a platform/OS-independent way than rely on the underlying OS,...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.