Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Parallel ping problems python puzzler

Reply
Thread Tools

Parallel ping problems python puzzler

 
 
amaccormack@gmail.com
Guest
Posts: n/a
 
      04-02-2007
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. However, as
soon as I do, the pings that do not get a response never return, so
their threads block forever and the program hangs. Environment is:
Python 2.3.3 (#1, Jan 5 2005, 15:24:27) [GCC 3.3.3 (SuSE Linux)] on
linux2 (running on SLES9)


pinglist=[]
class testit(Thread):
def __init__ (self,ip):
Thread.__init__(self)
self.ip = ip
self.status = -1
def run(self):
# -w 1 option to ping makes it timeout after 1 second
pingcmd="/bin/ping -c 2 -q -i 0.3 -w 1 %s >/dev/null" % ip
self.status = os.system(pingcmd)

def serping(ip):
pingcmd="/bin/ping -c 2 -q -i 0.3 -w 1 %s >/dev/null" % ip
os.system(pingcmd)

for machname in machlist:
#serping(machname) # this works in serial, and works
current = testit(machname) # this works in parallel, and
doesn't work
pinglist.append(current)
current.start()

# Wait for all pings to pong
for pingle in pinglist:
pingle.join()


Anyone got an idea what's going on? Is it the way that the ping
timeout works in SuSE is not thread-safe?

 
Reply With Quote
 
 
 
 
Miki
Guest
Posts: n/a
 
      04-02-2007
Hello,

> def run(self):
> # -w 1 option to ping makes it timeout after 1 second
> pingcmd="/bin/ping -c 2 -q -i 0.3 -w 1 %s >/dev/null" % ip

Not sure, but "ip" should be "self.ip", this might cause the problem.


HTH,
--
Miki <>
http://pythonwise.blogspot.com

 
Reply With Quote
 
 
 
 
amaccormack@gmail.com
Guest
Posts: n/a
 
      04-02-2007
On 2 Apr, 15:03, "Miki" <miki.teb...@gmail.com> wrote:
> Hello,
>
> > def run(self):
> > # -w 1 option topingmakes ittimeoutafter 1 second
> > pingcmd="/bin/ping-c 2 -q -i 0.3 -w 1 %s >/dev/null" % ip

>
> Not sure, but "ip" should be "self.ip", this might cause theproblem.


Sorry, that was my bad cutting-and-pasting to make a shorter example,
it IS self.ip in the real code. The REAL code works fine parallel or
serial as long as everything responds to the ping, but as soon as any
devices do not respond, it hangs in the threaded version.

 
Reply With Quote
 
Matimus
Guest
Posts: n/a
 
      04-02-2007
I wouldn't use threads for system calls. Checkout the subprocess
module instead. You can run multiple pipes at the same time
(subprocess.Popen). The python documentation for subprocess is pretty
good. There are a few examples. Actually, you don't even _need_ the
subprocess module, you can use os.popen for similar functionality.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Parallel in, Parallel out shift register Vivek Menon VHDL 0 06-10-2011 10:15 PM
Parallel in, Parallel out shift register Vivek Menon VHDL 5 06-08-2011 03:56 PM
Parallel port control with USB->Parallel converter Soren Python 4 02-14-2008 03:18 PM
WEP connection puzzler gromit12@gmail.com Wireless Networking 3 04-18-2006 11:28 PM
dropdown puzzler Jim Corey ASP .Net 1 01-16-2004 03:25 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57