-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht.py
More file actions
38 lines (28 loc) · 797 Bytes
/
t.py
File metadata and controls
38 lines (28 loc) · 797 Bytes
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
#!/usr/bin/env python
import subprocess
from threading import Thread
from Queue import Queue
num_threads = 3
ips = ['127.0.0.1', '10.103.13.156','10.103.13.145']
q = Queue()
def pingme(i, queue):
while True:
ip = queue.get()
print 'Thread %s pinging %s ' % (i, ip)
ret = subprocess.call('ping -c 1 %s' % ip, shell=True, stdout=open('c;/'), stderr=subprocess.STDOUT)
if ret == 0:
print '%s is alive!' % ip
else:
print '%s is down...' % ip
# start threads
for i in xrange(num_threads):
t = Thread(target=pingme, args=(i, q))
t.setDaemon(True)
t.start()
for ip in ips:
q.put(ip)
print 'main thread waiting...'
q.join()
print 'Done..'
if __name__ == '__main__':
pass