Question : what's wrong with my code to do concurrent traceroute to multiple IP addresses?

I am new to Python. When debugging the python code, I got the following error messages:

Exception in thread Thread-49:
Traceback (most recent call last):
  File "/usr/lib/python2.5/threading.py", line 486, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.5/threading.py", line 446, in run
    self.__target(*self.__args, **self.__kwargs)
TypeError: traceroute_worker() argument after * must be a sequence

The code is below:

Can anyone help me figure out what is wrong with the code?
Code Snippet:
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:
    def traceroute_worker(self, q): 
        proc, tracefile = q.get() 
        while True: 
            if proc.poll() is not None: 
                map_traceroute(tracefile)
                q.task_done() 
                break 
            time.sleep(5) 
            
    def do_traceroute(self, peers): 
        sites = []
        for p in peers:
            sites.append(p[0][0])
        print sites
 
        q = Queue() 
        for i in range(50): 
            t = Thread(target=self.traceroute_worker, args=(q)) 
            t.setDaemon(True) 
            t.start() 
            
        for item in sites: 
            out = open('some-file', 'w') 
            q.put(Popen(['/usr/bin/traceroute', item], stdout=out))
                    
        q.join()       # block until all tasks are done
Open in New Window Select All

Answer : what's wrong with my code to do concurrent traceroute to multiple IP addresses?

It is unfortunate that the "time" module has a function named "time". That is confusing.

"from time import time" goes into the "time" module, finds the function "time" and brings that into the local namespace.

Therefore time.sleep does not work, as time here is a function not a module.

You are trying to access the time module's sleep function. To do that:

Either "from time import sleep" and then "sleep(5)" or "import time" and then "time.sleep(5)"

Most of us prefer the latter.

Random Solutions  
 
programming4us programming4us