WIP: Independent child process monitoring #118 by bbengfort · Pull Request #134 · pythonprofilers/memory_profiler
So I see what you mean, however there is a subtle difference. The args to Popen if options.python = True are:
['python', '-m', 'memory_profiler', '--timestamp', '-o', 'mprofile_20170321080505.dat', 'examples/multiprocessing_example.py']
Whereas the args to Popen if passed as an executable are
`['python', 'examples/multiprocessing_example.py']`
In the first case, __main__ is memory_profiler.__main__ and examples/multiprocessing_example.py is run with execfile() on L1108 or exec() on L1119. This is correctly implemented (as discussed here) by embedding the exec into its own namespace (ns), thus making the exec'd file the equivalent of an import -- as a result, the functions inside examples/multiprocessing_example.py are not at the top level (but are nested under ns) and therefore cannot be pickled.
So that took me a while to figure out, but I think it makes sense. What do you think?