line_profiler icon indicating copy to clipboard operation
line_profiler copied to clipboard

Known issues when used with multiprocessing module?

Open alxempirical opened this issue 9 years ago • 9 comments

In my hands, line_profiler is failing to record information when multiprocessing.Pool.map is used to call the functions I'm targetting. I can probably put together a minimal test case, but I thought first I would check whether this is a known issue.

alxempirical avatar Apr 03 '16 21:04 alxempirical

Yeah, only the main process can be profiled.

rkern avatar Apr 03 '16 22:04 rkern

Thanks. I didn't notice that mentioned in the README.rst. Is it documented anywhere?

alxempirical avatar Apr 03 '16 22:04 alxempirical

An interesting feature would potentially be firing up line_profiler in each of the spawned interpreters and writing each interpreters results out to a file.

rawrgulmuffins avatar May 29 '16 18:05 rawrgulmuffins

If this is possible, this would be really useful.

rbnvrw avatar Jul 20 '16 08:07 rbnvrw

+1

krish7919 avatar Dec 09 '16 10:12 krish7919

+1

el3ment avatar Aug 31 '17 20:08 el3ment

Just ran into this myself, but was able to work around this by importing line_profiler in my script and creating a LineProfiler manually, which then gets copied to each child process. Finally, I had each process print out its stats on completion:

s = io.StringIO()
profile.print_stats(stream=s)
print(s.getvalue())

The use of StringIO is a hack to keep the output from the multiple processes from getting interleaved. Having each process output to a separate file should be pretty easy too.

tburmeister avatar Oct 31 '17 17:10 tburmeister

Just ran into this myself, but was able to work around this by importing line_profiler in my script and creating a LineProfiler manually, which then gets copied to each child process. Finally, I had each process print out its stats on completion:

s = io.StringIO()
profile.print_stats(stream=s)
print(s.getvalue())

The use of StringIO is a hack to keep the output from the multiple processes from getting interleaved. Having each process output to a separate file should be pretty easy too.

Tried it but still didn't work for me.. How did you do it?

3droj7 avatar Oct 11 '18 11:10 3droj7

This would be a nice feature to have.

jmlarson1 avatar May 11 '20 19:05 jmlarson1