from multiprocessing.dummy import Pool as ThreadPool import requests import random import time def func_main(thr): time1 = time.time() while True: proxy_line = proxy_lines[random.randint(1, len(proxy_lines)-1)].strip() session = requests.session() session.temeout = (5 , 5) Adapter = requests.adapters.HTTPAdapter(pool_connections = 1, pool_maxsize = 0, max_retries = 0) session.mount('http://', Adapter) session.mount('https://', Adapter) session.proxies = { 'http' : proxy_line, 'https' : proxy_line } try: request = session.post('http://www.yahex.ru/') request.close() break except Exception as exception: #print(exception) #print('Thread #' + str(thr + 1) + '|Reconnect|') pass time2 = time.time() - time1 global thr_quantity thr_quantity = thr_quantity - 1 print('Thread #' + str(thr + 1) + ' завершил работу|Прокси:' + proxy_line + '|Активных потоков:' + str(thr_quantity) + '|Время выполнения:{:.3f}'.format(time2)) return() #*******************************************************************# with open('C:\\proxy.txt' , 'r', encoding = 'utf-8') as proxy_file: proxy_lines = proxy_file.readlines() class Profiler(object): def __enter__(self): self._startTime = time.time() def __exit__(self, type, value, traceback): print("*************************\nВремя выполнения программы : {:.3f} sec".format(time.time() - self._startTime)) thr_quantity = 50 with Profiler() as p: with ThreadPool(thr_quantity) as pool: pool.map(func_main, range(thr_quantity)) pool.close() The problem is this: I run the code above in 50 threads, for example, 49 threads are executed, and on the 50th stream, everything hangs and the stream is not executed. Either on the last one hangs, or on the last 10 streams. Like that. I can not understand the reason. The screenshot below shows the speed of execution of threads. Last 10 minutes as much as he did. But in most cases it does not end. 
session.timeoutreplaced bysession.timeout? - jfs