473,325 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Parallel ping problems python puzzler

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?

Apr 2 '07 #1
3 1813
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 <mi*********@gmail.com>
http://pythonwise.blogspot.com

Apr 2 '07 #2
On 2 Apr, 15:03, "Miki" <miki.teb...@gmail.comwrote:
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.

Apr 2 '07 #3
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.

Apr 2 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alberto Vera | last post by:
Hello: Is it possible to make "ping" from Python and get statistics like using command prompt from Windows? How Can I capture them into variables? Thanks Pinging XXXX.XXXX.XXXX.XXXX with...
0
by: Emile van Sebille | last post by:
QOTW: "Oddly enough it is in Python that I have had the most fun programming. It is in Python that I find myself not only the most expressive but the most elegant in my programming. In Python my...
2
by: Count László de Almásy | last post by:
Greetings, I'm in need of a simple GUI application that "monitors" a range of hosts using ping and reports on their status by changing the panel color for that host (i.e, green for pingable, red...
5
by: SolaFide | last post by:
I have 2 threads that I want to run at the same time: for instance: from threading import Thread class test(Thread): def run(self): while True: get(asdf) class test2(Thread):
43
by: parallelpython | last post by:
Has anybody tried to run parallel python applications? It appears that if your application is computation-bound using 'thread' or 'threading' modules will not get you any speedup. That is because...
7
by: Linus Cohen | last post by:
Hi all, I'm a newbie to python and programming in general, so I wanted a simple project to start off. What I'm trying to do here is write a python command-line ping program, much like the Unix and...
1
by: Mauro \Baba\ Mascia | last post by:
Hi, this is my question: I want to know if several switch (about 50) in a big lan are up and then know their MAC addresses to do a list that contains host name, ip and mac. I know only the range...
1
by: Karl Kobata | last post by:
Hi Fredrik, This is exactly what I need. Thank you. I would like to do one additional function. I am not using the tokenizer to parse python code. It happens to work very well for my...
1
by: ScottZ | last post by:
With python 2.6 and wxpython I'm trying to create a system tray icon application based around an example found here:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.