import urllib import threading from Queue import Queue import time def

 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
import urllib
import threading
from Queue import Queue
import time
def checkit():
line = q.get()
print 'checking %s' % line
x = urllib.urlopen("http://www.{0}".format(line)).getcode()
print str(x)
q.task_done()
q = Queue()
f = open("urls.txt", "r")
try:
for line in f:
q.put(line)
finally:
f.close()
while True:
if q.qsize() == 0: break
print q.qsize(), Threads_Number
if q.qsize() > 0:
for x in xrange(q.qsize()):
t = threading.Thread(target=checkit)
t.start()
else:
time.sleep(0.1)