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(pingc md)
def serping(ip):
pingcmd="/bin/ping -c 2 -q -i 0.3 -w 1 %s >/dev/null" % ip
os.system(pingc md)
for machname in machlist:
#serping(machna me) # 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? 3 1837
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*********@gm ail.com> http://pythonwise.blogspot.com
On 2 Apr, 15:03, "Miki" <miki.teb...@gm ail.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.
I wouldn't use threads for system calls. Checkout the subprocess
module instead. You can run multiple pipes at the same time
(subprocess.Pop en). 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 32 bytes of data:
|
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 code
is the clearest and most concise. I don't for one instant feel
constrained by Python. I feel liberated by it." -- Steve Lamb
"After a few hours with Python, I was already better at object-oriented
Python than I ever was at...
|
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 for unreachable).
Does anyone know of any existing opensource program that does this?
Preferably Python so I can extend it easily.
If not, what tools would you recommend I write this kind of app in?
|
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):
|
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
python interpreter uses GIL(Global Interpreter Lock) for internal
bookkeeping. The later allows only one python byte-code instruction to
be executed at a time even if you have a multiprocessor computer.
To overcome this limitation, I've created...
| |
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 Windows ping
programs. I've got this much worked out already:
class ping
def PING(IP, pings, size):
and that's where I stop, because I realize I have no idea how to make
|
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 of their IP addresses (the host name it's simply
to know using socket.gethostn.
The first idea it's to ping all ip, parse the response and then execute
the command "arp -a" and parse the response.
However this way depends on the operating...
|
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 application.
However, I would like either or both of the following variance:
1) I would like to add 2 other characters as comment designation
2) write a module that can readline, modify the line as required, and
finally, this module can be used as the...
|
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:
http://codeboje.de/MailSneaker-Part-3-SystemTrayTaskBar-Icons-with-Python-and-wxPython/
The application will simply change the systray icon based on if an ip
address is online or not.
The ping portion looks like this:
if os.name == "nt": # Windows
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |