Good day, actually the problem is in using ThreadPoolExecutor from the concurrent.futures package, exactly in CentOS 6 when executing the following code:
from concurrent.futures import ThreadPoolExecutor, wait executor = ThreadPoolExecutor() futures = () for i in range(25): futures += executor.submit(lambda: print(i)), wait(futures) The result is:
1 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Traceback (most recent call last): File "thread.py", line 9, in <module> futures += executor.submit(lambda: print(i)), File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 115, in submit self._adjust_thread_count() File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 134, in _adjust_thread_count t.start() File "/usr/local/lib/python3.6/threading.py", line 846, in start _start_new_thread(self._bootstrap, ()) RuntimeError: can't start new thread In this case, the threshold size of the pool is 24, this behavior does not manifest if you create threads manually, that is, through threading.Thread , also on other Linux OS, the same ThreadPoolExecutor performs normally. It’s hard not to believe that this is a Python bug specifically for CentOS 6. It was tested on Python-3.5 and 3.6. What can be wrong? Thanks for attention!
max_workersparameter (look at the limit on the number of threads for the process / system ) and callshutdown():with ThreadPoolExecutor(max_workers=2) as executor: executor.map(print, range(25)): think howlambda: print(i)differs fromprint(lambda i=i: print(i)). - jfsdocker run --rm -v "$PWD:/prj" nbearson/centos6-python3 python3 /prj/so-user-triplustri.py- jfslambda i: print(i)in a loop - and I knew that somebody would notice) - triplustri