|
关于python中的多线程与并发
在用python多线程构造并发请求的时候,遇到如下的“thread.error: can't start new thread”错误:
写道
Traceback (most recent call last):
File "push_test.py", line 71, in <module>
test()
File "push_test.py", line 65, in test
mrun(str(i)).start()
File "/usr/local/lib/python2.7/threading.py", line 495, in start
_start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread
分别在windows(32bit)和linux(64bit)下测试,情况差不多;而且可以开启的thread基本每次都停留在420左右!
google之,参考了stackoverflow和bytes上的一些案例,距离问题本质还有些距离,随后翻阅了这些,分享之:
1 一些术语和项目
python : thread, threading , processing ,
线程池 http://en.wikipedia.org/wiki/Thread_pool_pattern
socket: select , epoll
stackless http://www.stackless.com
greenlet, eventlet
2 如何自己实现一个简单的线程池? 以及 threadpool 模块的使用 http://www.juziblog.com/?p=326001
3 来自 Elias 的一篇文章,内容叫全面,很专业,点击率也不低:Python几种并发实现方案的性能比较 http://www.elias.cn/Python/PyConcurrency
4 到底多少线程才算多? http://stackoverflow.com/questions/481970/how-many-threads-is-too-many
PS: 查看linux的一些上限参数
cat /proc/sys/kernel/threads-max
ulimit -a
在linux上的python中可以 import resource 模块后,调用resource的相关方法查看系统上限参数。 |
|
|