[New-bugs-announce] [issue5092] weird memory usage in multiprocessing module
Jerzy
report at bugs.python.org
Thu Jan 29 01:13:40 CET 2009
New submission from Jerzy <jerzyo at genesilico.pl>:
Hi
I am using the multiprocessing mudule and I found a very weird thing.
It seems that that the result of one fragment of the code depends on the
fragment of the code that is after it, which should not happen.
My script looks like this
import time
import multiprocessing
import sys
def f():
sys.stderr.write(str(len(l))+"\n")
print len(l)
#del l
while(True):
time.sleep(1)
l=[]
for i in range(2*1000*1000):
l.append(str(i))
process = multiprocessing.Process(target=f)
process.start()
while(True):
time.sleep(1)
And its output is as expected:
2000000
2000000
but when I uncoment the 'del l' line I get:
File
"/home/jerzyo/programs/python2.6/Python-2.6.1/Lib/multiprocessing/process.py",
line 231, in _bootstrap
self.run()
File
"/home/jerzyo/programs/python2.6/Python-2.6.1/Lib/multiprocessing/process.py",
line 88, in run
self._target(*self._args, **self._kwargs)
File "bin/momory.py", line 6, in f
sys.stderr.write(str(len(l))+"\n")
UnboundLocalError: local variable 'l' referenced before assignment
How is that? The line that deletes l is after the printing line. How
python interpreter knows that l will be deleted. This is a very anomalus
behaviour and should never happen.
By the way. Is there any way to free some parts of memory in child
process. Suppose I wand to create 100 child processes that do not use
the l list. How can I avoid making 100 copies of l in child processes.
That is my firs post and won't come here very often, so please answer
also to my email (if it is not automaic). I am running python 2.6.1 on
ubuntu 8.04 32bit.
jerzy
----------
messages: 80731
nosy: Orlowski
severity: normal
status: open
title: weird memory usage in multiprocessing module
type: resource usage
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5092>
_______________________________________
More information about the New-bugs-announce
mailing list