ограничение количества потоков

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
threadcount = 32768
lines = urlopen("")
mythreads = []
for subnet in lines:
for ip in IP(subnet):
th1 = scan(str(ip),'8080')
th1.start()
th2 = scan(str(ip),'3128')
th2.start()
mythreads.append(th1)
mythreads.append(th2)
if len(mythreads) == threadcount:
print len(mythreads)
while len(mythreads) > 0:
th = mythreads.pop()
th.join()
del(th)
if len(mythreads) > 0:
print len(mythreads)
while len(mythreads) > 0:
th = mythreads.pop()
th.join()
del(th)
print time.ctime()