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!

  • Try explicitly max_workers parameter (look at the limit on the number of threads for the process / system ) and call shutdown() : with ThreadPoolExecutor(max_workers=2) as executor: executor.map(print, range(25)) : think how lambda: print(i) differs from print ( lambda i=i: print(i) ). - jfs
  • your code works on CentOS 6 and Python 3: docker run --rm -v "$PWD:/prj" nbearson/centos6-python3 python3 /prj/so-user-triplustri.py - jfs
  • @jsf - the question is removed, there were restrictions at the level of the virtual machine, thanks. About lambda i: print(i) in a loop - and I knew that somebody would notice) - triplustri
  • This question may be useful to other people (for this site there is). If you can, leave your answer (explicitly the reason for the RuntimeError, describe with words what command the limit was found, how it was changed, that is, how the problem was resolved) - this is clearly welcomed . - jfs

0