BTW: python is great! ;-)
#!/usr/bin/env python
import sys, urllib, urllib
from threading import Thread, Lock
class webThread(Thread):
def __init__(self, url):
self.url = url
Thread.__init__(self)
def run(self):
remotefile = urllib.urlopen(self.url)
data = remotefile.read()
remotefile.close()
stdout_mutex.acquire()
print "=== %s ===" % self.url
print data
stdout_mutex.release()
if __name__ == '__main__':
if len(sys.argv) <>" % sys.argv[0]
sys.exit(1)
else:
threads = []
stdout_mutex = Lock()
sys.stdout.flush()
for url in sys.argv[1:]:
t = webThread(url)
t.start()
threads.append(t)
for t in threads:
t.join()
No comments:
Post a Comment