4
我已经安装了Python 3的嵌入式系统(ARMv5tejl AT91SAM9X25,运行基于buildroot的rootfs的128MB RAM)。我已经让系统运行了很多天,并且我已经开始对它进行一些python开发工作,但似乎遇到了创建新线程的问题。Python无法启动新线程,但没有启动线程限制
如果我尝试运行下面的程序:
Type "help", "copyright", "credits" or "license" for more information.
>>> import threading
>>> import time
>>> def func():
... i = 0
... while True:
... i += 1
... print(i)
... time.sleep(1)
...
>>>
>>> func()
1
2
3
^CTraceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in func
KeyboardInterrupt
>>> t = threading.Thread(target=func)
>>> t.start()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.4/threading.py", line 850, in start
RuntimeError: can't start new thread
>>>
正如你所看到的,试图启动线程的时候,我得到上述错误。在线初步搜索似乎表明问题可能是由于系统运行到线程限制。这里的ulimit -a的输出:
# 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
使用this method,线程我的系统上的总数为75,这是远远低于961这里限制是我目前的内存状态:
# free -m
total used free shared buffers cached
Mem: 120 118 2 60 0 65
-/+ buffers/cache: 52 67
Swap: 0 0 0
我也运行内存压缩机运行echo 1 > /proc/sys/vm/compact_memory
。
我想如果我重新启动设备(因为代码是已知的工作代码),一切都会正常工作,但由于我现在有设备处于此状态,所以我很想尝试了解问题是什么。
线程无疑是启用的,因为我在使用线程的单元上编写了Python软件。这就是现在,运行该软件失败,因为解释器无法创建线程。 –
我想知道OP是否解决过这个问题? – holdenweb