title: Python can't start new thread, but not hitting thread limit
body: <p>I've got an embedded system (armv5tejl AT91SAM9X25 with 128MB RAM running a buildroot-based rootfs) with Python 3 installed. I've left the system running for many days now and I've come to do some python development work on it, but seem to run into a problem creating new threads.</p>
  
  <p>If I try to run the following program:</p>
  
  <pre><code>Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import threading
  &gt;&gt;&gt; import time
  &gt;&gt;&gt; def func():
  ...     i = 0
  ...     while True:
  ...         i += 1
  ...         print(i)
  ...         time.sleep(1)
  ...
  &gt;&gt;&gt;
  &gt;&gt;&gt; func()
  1
  2
  3
  ^CTraceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "&lt;stdin&gt;", line 6, in func
  KeyboardInterrupt
  &gt;&gt;&gt; t = threading.Thread(target=func)
  &gt;&gt;&gt; t.start()
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "/usr/lib/python3.4/threading.py", line 850, in start
  RuntimeError: can't start new thread
  &gt;&gt;&gt;
  </code></pre>
  
  <p>As you can see, when trying to start the thread, I get the above error. Some initial searching online seems to indicate that the problem may be due to the system running into thread limits. Here is the output of ulimit -a:</p>
  
  <pre><code># ulimit -a
  core file size          (blocks, -c) 0
  data seg size           (kbytes, -d) unlimited
  scheduling priority             (-e) 0
  file size               (blocks, -f) unlimited
  pending signals                 (-i) 961
  max locked memory       (kbytes, -l) 64
  max memory size         (kbytes, -m) unlimited
  open files                      (-n) 1024
  pipe size            (512 bytes, -p) 8
  POSIX message queues     (bytes, -q) 819200
  real-time priority              (-r) 0
  stack size              (kbytes, -s) 8192
  cpu time               (seconds, -t) unlimited
  max user processes              (-u) 961
  virtual memory          (kbytes, -v) unlimited
  file locks                      (-x) unlimited
  </code></pre>
  
  <p>Using <a href="https://superuser.com/a/547043/132615">this method</a>, the total number of threads on my system is 75, which is way below the limit of 961. Here is my current memory status:</p>
  
  <pre><code># free -m
               total       used       free     shared    buffers     cached
  Mem:           120        118          2         60          0         65
  -/+ buffers/cache:         52         67
  Swap:            0          0          0
  </code></pre>
  
  <p>I've also run the memory compactor by running <code>echo 1 &gt; /proc/sys/vm/compact_memory</code>.</p>
  
  <p>I imagine that everything would work fine if I rebooted the device (since the code is known working code), but since I have the device in this state right now, I'm keen on trying to understand what the problem is.</p>