Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I'm using Python to invoke another program in a sub-process. I've noticed my memory sometimes gets so large as to crash the system, and I'm wondering if I'm not correctly cleaning up the memory som...
#4: Post edited
Freeing sub-process resources?
- I'm using Python to invoke another program in a sub-process. I've noticed my memory sometimes gets so large as to crash the system, and I'm wondering if I'm not correctly cleaning up the memory somehow.
- Here's what I have:
- ```
- children = []
- fruits = ["apple", "banana", "cherry"]
for fruit in fruit:- children.append(subprocess.Popen(["fruitProgram", fruit]))
- while len(children) > 0:
- child = children.pop()
- child.wait()
- subprocess.run("doStuffWithFruitProgramOutput")
- ```
- I've had my `doStuffWithFruitProgramOutput` crash due to lack of memory when run like this, but not when run by itself. Is `child.wait()` not enough to free the child process resources?
- I tried adding `gc.collect()` after clearing `children`, and that doesn't seem to have helped.
- Is there something else I need to be doing? Or am I barking up the wrong tree here, and my problem is somewhere else?
- I'm using Python to invoke another program in a sub-process. I've noticed my memory sometimes gets so large as to crash the system, and I'm wondering if I'm not correctly cleaning up the memory somehow.
- Here's what I have:
- ```
- children = []
- fruits = ["apple", "banana", "cherry"]
- for fruit in fruits:
- children.append(subprocess.Popen(["fruitProgram", fruit]))
- while len(children) > 0:
- child = children.pop()
- child.wait()
- subprocess.run("doStuffWithFruitProgramOutput")
- ```
- I've had my `doStuffWithFruitProgramOutput` crash due to lack of memory when run like this, but not when run by itself. Is `child.wait()` not enough to free the child process resources?
- I tried adding `gc.collect()` after clearing `children`, and that doesn't seem to have helped.
- Is there something else I need to be doing? Or am I barking up the wrong tree here, and my problem is somewhere else?
#2: Post edited
- I'm using Python to invoke another program in a sub-process. I've noticed my memory sometimes gets so large as to crash the system, and I'm wondering if I'm not correctly cleaning up the memory somehow.
- Here's what I have:
- ```
- children = []
- fruits = ["apple", "banana", "cherry"]
- for fruit in fruit:
- children.append(subprocess.Popen(["fruitProgram", fruit]))
- while len(children) > 0:
- child = children.pop()
- child.wait()
- subprocess.run("doStuffWithFruitProgramOutput")
- ```
I've had my `doStuffWithFruitProgramOutput` crash due to lack of memory when run like this, but not when run by itself. is `child.wait()` not enough to free the child process resources?- I tried adding `gc.collect()` after clearing `children`, and that doesn't seem to have helped.
- Is there something else I need to be doing? Or am I barking up the wrong tree here, and my problem is somewhere else?
- I'm using Python to invoke another program in a sub-process. I've noticed my memory sometimes gets so large as to crash the system, and I'm wondering if I'm not correctly cleaning up the memory somehow.
- Here's what I have:
- ```
- children = []
- fruits = ["apple", "banana", "cherry"]
- for fruit in fruit:
- children.append(subprocess.Popen(["fruitProgram", fruit]))
- while len(children) > 0:
- child = children.pop()
- child.wait()
- subprocess.run("doStuffWithFruitProgramOutput")
- ```
- I've had my `doStuffWithFruitProgramOutput` crash due to lack of memory when run like this, but not when run by itself. Is `child.wait()` not enough to free the child process resources?
- I tried adding `gc.collect()` after clearing `children`, and that doesn't seem to have helped.
- Is there something else I need to be doing? Or am I barking up the wrong tree here, and my problem is somewhere else?
#1: Initial revision
Freeing sub-process resources?
I'm using Python to invoke another program in a sub-process. I've noticed my memory sometimes gets so large as to crash the system, and I'm wondering if I'm not correctly cleaning up the memory somehow. Here's what I have: ``` children = [] fruits = ["apple", "banana", "cherry"] for fruit in fruit: children.append(subprocess.Popen(["fruitProgram", fruit])) while len(children) > 0: child = children.pop() child.wait() subprocess.run("doStuffWithFruitProgramOutput") ``` I've had my `doStuffWithFruitProgramOutput` crash due to lack of memory when run like this, but not when run by itself. is `child.wait()` not enough to free the child process resources? I tried adding `gc.collect()` after clearing `children`, and that doesn't seem to have helped. Is there something else I need to be doing? Or am I barking up the wrong tree here, and my problem is somewhere else?