GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — WIP: Independent child process monitoring #118 by bbengfort · Pull Request #134 · pythonprofilers/memory_profiler Conversation
Contributor
This pull request is a start at resolving #118 -- as mentioned in that issue, I've created a function I've also updated the reference from #71 to wrap the entire yield in try/except and yield 0.0 if the race condition occurs; but this needs to be checked. Including this into the main The next steps are to merge
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
bbengfort
commented
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about this, I think this was just a carry over from the historical merge; I can reset back to the original if needed.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
bbengfort
commented
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So here is the line where I independently collect the memory of each child and add them to the .dat file with the "CHLD#" key. If
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
bbengfort
commented
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And then obviously, plot needs to be adapted to plot all the children.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Contributor
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Collaborator
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
fabianp
requested changes
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How hard do you think it would be to remove this limitation?, i.e., to track children even if the function is not @Profile'd
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am confused, as the example works fine even without decorated functions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
|
|
Unfortunately, I think that the pickle error is a product of multiprocessing library: functions can only be pickled if they're defined at the top level and when you run it by creating a subprocess in I can see if I can change the example (though that may be difficult), but I also wanted to note that the problem exists even with the original version of the http://stackoverflow.com/questions/8804830/python-multiprocessing-pickling-error |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| stream.write("CHLD {0} {1:.6f} {2:.4f}\n".format(idx, chldmem, time.time())) | ||
| else: | ||
| ret.append(mem_usage) | ||
| if multiprocess: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here is the first place where I don't return multiple values and instead warn
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| ret.append(mem_usage) | ||
|
|
||
| if multiprocess: | ||
| warnings.warn("use include_children not multiprocess without a stream") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here is the second place where I don't return multiple values and instead warn
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
For the pickling, what I find strange is that both commands (with and without the "python" word in mprof) should be identical, as per lines 217-223 of mprof. Not sure why multiprocessing fails only on one of these cases since they should be executed the same way. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
So I see what you mean, however there is a subtle difference. The args to Popen if Whereas the args to Popen if passed as an executable are In the first case, So that took me a while to figure out, but I think it makes sense. What do you think? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the explanation and your time. I've merged the PR and added a small patch (52c5788) so that the example can be run without the python keyword. Thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sure thing, let me know if there is anything else I can help with; sorry that this feature took so long! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| except psutil.NoSuchProcess: | ||
| # https://github.com/fabianp/memory_profiler/issues/71 | ||
| pass | ||
| mem += sum(_get_child_memory(process, meminfo_attr)) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hi, quick question, as processes in modern linux share common memory after forking from their parent and only copy it on writes, wouldn't this sum report the wrong number?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I'm not sure of the behavior of psutil with regards to linux forks; I simply used the same meminfo_attr as the summation function. If that's true then this is indeed a problem, but I'd guess that we'd have to dig into psutil to figure it out.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It would indeed be great to know (but I'm clueless here)
On Jun 12, 2017 12:09 PM, "Benjamin Bengfort" <[email protected]> wrote:
*@bbengfort* commented on this pull request.
------------------------------
In memory_profiler.py
<https://github.com/fabianp/memory_profiler/pull/134#discussion_r121500525>:
@@ -111,12 +143,7 @@ def ps_util_tool():
else 'get_memory_info'
mem = getattr(process, meminfo_attr)()[0] / _TWO_20
if include_children:
- try:
- for p in process.children(recursive=True):
- mem += getattr(p, meminfo_attr)()[0] / _TWO_20
- except psutil.NoSuchProcess:
- # https://github.com/fabianp/memory_profiler/issues/71
- pass
+ mem += sum(_get_child_memory(process, meminfo_attr))
Unfortunately I'm not sure of the behavior of psutil with regards to linux
forks; I simply used the same meminfo_attr as the summation function. If
that's true then this is indeed a problem, but I'd guess that we'd have to
dig into psutil to figure it out.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<https://github.com/fabianp/memory_profiler/pull/134#discussion_r121500525>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAQ8h-Xtff8eOlmZVoMv3dePOSis4Wziks5sDYzxgaJpZM4MhiXU>
.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.