Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107057

Re: Python garbage collection: not releasing memory to OS!

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Michael Torrie <torriem@gmail.com>
Newsgroups comp.lang.python
Subject Re: Python garbage collection: not releasing memory to OS!
Date Fri, 15 Apr 2016 07:59:47 -0600
Lines 25
Message-ID <mailman.25.1460729198.6324.python-list@python.org> (permalink)
References <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com> <5710F3D3.7010603@gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de NijXXLxh6GjXsSM33riVdA7oFLV21X/2oMD7lZPqF+Gg==
Return-Path <torriem+gmail@torriefamily.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'memory.': 0.05; 'finished.': 0.07; 'lines.': 0.07; 'problem?': 0.07; 'spawn': 0.09; 'python': 0.10; 'itself.': 0.11; 'subject:not': 0.11; 'output': 0.13; '(completely': 0.16; 'correctly,': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'released.': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'config': 0.18; 'python?': 0.18; 'input': 0.18; 'amounts': 0.22; 'file.': 0.22; 'am,': 0.23; 'finished': 0.23; "python's": 0.23; 'tried': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'header:User-Agent:1': 0.26; 'separate': 0.27; 'question': 0.27; 'function': 0.28; 'concern': 0.29; 'code': 0.30; 'task': 0.30; 'checked': 0.31; 'guess': 0.31; 'run': 0.33; 'message- id:@gmail.com': 0.34; 'file': 0.34; 'returning': 0.35; 'skip:* 20': 0.35; 'stopped': 0.35; 'there': 0.36; 'data.': 0.36; 'to:addr :python-list': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:org': 0.37; 'why': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'your': 0.60; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'is.': 0.63; 'facilities': 0.72; '**is': 0.84; 'rises': 0.84; 'killed': 0.91
X-Virus-Scanned amavisd-new at torriefamily.org
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2
In-Reply-To <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <5710F3D3.7010603@gmail.com>
X-Mailman-Original-References <215cf2a4-c2fa-41d0-8c49-23b9494234d4@googlegroups.com>
Xref csiph.com comp.lang.python:107057

Show key headers only | View raw


On 04/15/2016 04:25 AM, cshintov@gmail.com wrote:
> The input was a 4MB file. Even after returning from the 'fileopen'
> function the 4MB memory was not released. I checked htop output while
> the loop was running, the resident memory stays at 14MB. So unless
> the process is stopped the memory stays with it.

I guess the question is, why is this a problem?  If there are no leaks,
then I confess I don't understand what your concern is.  And indeed you
say it's not leaking as it never rises above 14 MB.

Also there are ways of reading a file without allocating huge amounts of
memory.  Why not read it in in chunks, or in lines.  Take advantage of
Python's generator facilities to process your data.

> So if the celery worker is not killed after its task is finished it
> is going to keep the memory for itself. I know I can use
> **max_tasks_per_child** config value to kill the process and spawn a
> new one. **Is there any other way to return the memory to OS from a
> python process?.**

Have you tried using the subprocess module of python? If I understand it
correctly, this would allow you to run python code as a subprocess
(completely separate process), which would be completely reaped by the
OS when it's finished.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python garbage collection: not releasing memory to OS! cshintov@gmail.com - 2016-04-15 03:25 -0700
  Re: Python garbage collection: not releasing memory to OS! Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2016-04-15 08:24 -0400
  Re: Python garbage collection: not releasing memory to OS! Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-04-15 14:02 +0100
  Re: Python garbage collection: not releasing memory to OS! Michael Torrie <torriem@gmail.com> - 2016-04-15 07:59 -0600
  Re: Python garbage collection: not releasing memory to OS! Sam <python@net153.net> - 2016-04-15 09:27 -0500

csiph-web