Python_2  1.0
Classes | Functions
_06_ping Namespace Reference

Let's say that you want to check the availability of many computers on a network ... More...

Classes

class  testit
 Class for pinging a given IP, in its own thread. More...
 

Functions

def main (argv=None)
 

Detailed Description

Let's say that you want to check the availability of many computers on a network ...

you'll use ping. But there's a problem - if you "ping" a host that's not running, it takes a while to timeout. Therefore, when you check through a whole lot of systems that aren't responding, (the very time a quick response is probably needed), it can take an age.

We're going to run code concurrently to ping each host computer and (being Python), we create an object for each of the concurrent tests (threads) we wish to run. Each of these objects inherits from the Thread class, so that we can use all of the logic already written in Python to provide our parallelism.

Although the constructor builds the thread, it does not start it; rather, it leaves the thread based object at the starting gate. The start method on the testit object actually triggers it off - internally, by triggering the run method of the testit class, and then returning to the calling code. In other words, this is the point at which the parallel processing actually starts, and the run method is called indirectly (via a callback, in a similar way to sort and map make callbacks).

Once parallel processes have started, you'll want some way to bring the responses back together at the end, and in this first simple example, it is used a join.

Author
Paulo Roma
Since
22/07/2009
See also
http://www.wellho.net/solutions/python-python-threads-a-first-example.html

Function Documentation

◆ main()

def _06_ping.main (   argv = None)

References _10_tkmpg123.clear().