I’ve written beneath python script simply to invoke parallel threads of a command
nslookup linux-host01 dns-server, i am Simply making an attempt to flood the DNS Server
dns-server with a number of variety of queries in parallel approach.
As an argument to this script i am passing a
hostlist file instance
linux-host02 and so on.
To realize this i am utilizing
threading module with the beneath code and this works wonderful, Nonetheless, i am utilizing the the threading first time therefore wish to know if this may be simplified of enhanced additional.
import os import threading from sys import argv, exit lock = threading.Lock() hostfile = argv lst =  with open(hostfile, 'r') as frb: for line in frb: lst.append(line.strip("n")) threads =  thread_count = len(lst) def pop_queue(): host = None lock.purchase() if lst: host = lst.pop() lock.launch() return host def dequeue(): whereas len(lst) != 0: host = pop_queue() if not host: return None else: dolookup(host) def dolookup(identify): whereas True: os.system("/usr/bin/nslookup %s dns-test01" %identify) for i in vary(thread_count): t = threading.Thread(goal=dequeue) t.begin() print "began thread %s" %i threads.append(t) [t.join() for t in threads]
Recognize any assistance on this.