OSError:[Errno 12]无法分配内存

时间:2017-12-19 09:00:49

标签: python django apache python-multiprocessing

我已经实现了下面的多处理代码,它可以同时处理多个请求,但是我遇到了错误。为此,我使用生产者和消费者的概念,在队列中生成放置过程,消费者使用该过程并做一些JOB。

Traceback (most recent call last):
p.start()
File "/usr/lib/python2.7/multiprocessing/process.py", line 130, in start
self._popen = Popen(self)
File "/usr/lib/python2.7/multiprocessing/forking.py", line 121, in __init__
self.pid = os.fork()
OSError: [Errno 12] Cannot allocate memory


queue = Queue()
lock = Lock()
producers = []
consumers = []
for frame in frames:
    `enter code here`producers.extend([Process(target=self.producer, args=(queue, lock, frame)) for i in xrange(cpu_count())])
for i in range(50):
    p = Process(target=self.consumer, args=(queue, lock))
    p.daemon = True
    consumers.append(p)

for p in producers:
    #time.sleep(random.randint(0, 5))
    p.start()

for c in consumers:
    #time.sleep(random.randint(0, 5))

c.start()

# Like threading, we have a join() method that synchronizes our program
for p in producers:
   p.join()

u_end = time.time()
print u_start, u_end
print('Parent process exiting...')

0 个答案:

没有答案