我正在运行的 CGI 脚本出现以下错误......
Traceback (most recent call last):, referer: http://mysite/cgi-bin/dev/testing.py
File "/var/www/cgi-bin/dev/testing.py", line 908, in <module>, referer: http://mysite/cgi-bin/dev/testing.py
webpage(), referer: http://mysite/cgi-bin/dev/testing.py
File "/var/www/cgi-bin/dev/testing.py", line 899, in webpage, referer: http://mysite/cgi-bin/dev/testing.py
getResults(form), referer: http://mysite/cgi-bin/dev/testing.py
File "/var/www/cgi-bin/dev/testing.py", line 557, in getResults, referer: http://mysite/cgi-bin/dev/testing.py
new_nums = processNums(nums), referer: http://mysite/cgi-bin/dev/testing.py
File "/var/www/cgi-bin/dev/testing.py", line 328, in processNums, referer: http://mysite/cgi-bin/dev/testing.py
t.start(), referer: http://mysite/cgi-bin/dev/testing.py
File "/usr/lib64/python2.6/threading.py", line 471, in start, referer: http://mysite/cgi-bin/dev/testing.py
_start_new_thread(self.__bootstrap, ()), referer: http://mysite/cgi-bin/dev/testing.py
thread.error: can't start new thread, referer: http://mysite/cgi-bin/dev/testing.py
这可能是我机器上的 ulimit 问题,但我想和你们一起检查我的代码。这是我用于线程的代码....
import Queue
import multiprocessing
from threading import Thread
def processNums(nums):
new_nums = []
queue = Queue.Queue()
for num in nums:
queue.put(num)
thread_num = multiprocessing.cpu_count()
for x in range(0,thread_num):
t = Thread(target=multNum,args=(queue,new_nums,))
t.setDaemon(True)
t.start()
queue.join()
return new_nums
def multNum(queue,new_nums):
while True:
try: num = queue.get()
except: break
# do something....
new_num = num*123456
new_nums.append(new_num)
queue.task_done()
print processNums([54,12,87,3268,2424,148,5,9877])
输出 [6666624, 1481472, 10740672, 403454208, 299257344, 18271488, 617280, 1219374912]
这是我的代码的一个真正淡化的版本(这里有很多我无法复制所有代码)但我怀疑我的问题出在此处。我的问题是......我应该以某种方式关闭这些线程吗?python不会自动做到这一点吗?或者这是 apache 或我的 linux 服务器的配置问题?这是我第一次看到这个错误,但这也是我第一次使用我正在使用的数据集运行这个应用程序。该数据集生成数千个线程。谢谢。