【发布时间】:2017-07-07 09:01:09
【问题描述】:
我正在使用多线程来处理图像。
它在我有足够内存的电脑上运行良好(处理许多图像时增加 2~3 GB),但我的服务器只有 1GB 内存,代码无法正常工作。
有时以Segmentation fault结尾,有时:
Exception in thread Thread-13:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 763, in run
self.__target(*self.__args, **self.__kwargs)
File "passportRecognizeNew.py", line 267, in doSomething
...
代码:
import threading
def doSomething(image):
# picture processing code
print("processing over")
threads = []
for i in range(20):
thread = threading.Thread(target=doSomething, args=("image",))
threads.append(thread)
for t in threads:
t.setDaemon(True)
t.start()
t.join()
print("All over")
如何解决这个问题或任何控制内存使用的方法?
【问题讨论】:
标签: python multithreading image-processing memory-management out-of-memory