I wrote a simple script, which using threads to retrieve data from service.
__author__ = 'Igor'
import requests
import time
from multiprocessing.dummy import Pool as ThreadPool
ip_list = []
good_ip_list = []
bad_ip_list = []
progress = 0
with open('/tmp/ip.txt') as f:
ip_list = f.read().split()
def process_request(ip):
global progress
progress += 1
if progress % 10000 == 0:
print 'Processed ip:', progress, '...'
r = requests.get('http://*****/?ip='+ip, timeout=None)
if r.status_code == 200:
good_ip_list.append(ip)
elif r.status_code == 400:
bad_ip_list.append(ip)
else:
print 'Unknown http code received, aborting'
exit(1)
pool = ThreadPool(16)
try:
pool.map(process_request, ip_list)
except:
for name, ip_list in (('/tmp/out_good.txt', good_ip_list), ('/tmp/out_bad.txt', bad_ip_list)):
with open(name, 'w') as f:
for ip in ip_list:
print>>f, ip
But after some requests processed (40k-50k) i receive:
Exception in thread Thread-7 (most likely raised during interpreter shutdown): Traceback (most recent call last): Process finished with exit code 0
Tried to change service settings:
<timeout>999</timeout>
<connectionlimit>600</connectionlimit>
<httpthreads>32</httpthreads>
<workerthreads>128</workerthreads>
but still same error. Can anybody help me - what's wrong?
progress += 1in language with mutable data and using multiple threads w/o any protection... I stopped looking at that point ;) - iced