This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Orlowski
Recipients Orlowski
Date 2009-01-29.00:13:37
SpamBayes Score 3.6082248e-14
Marked as misclassified No
Message-id <1233188020.97.0.306560555097.issue5092@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2009-01-29 00:13:41Orlowskisetrecipients: + Orlowski
2009-01-29 00:13:40Orlowskisetmessageid: <1233188020.97.0.306560555097.issue5092@psf.upfronthosting.co.za>
2009-01-29 00:13:39Orlowskilinkissue5092 messages
2009-01-29 00:13:37Orlowskicreate