-
-
Notifications
You must be signed in to change notification settings - Fork 447
Enable coverage measurement of code run by multiprocessing.Process
#117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Original comment by amcnabb8 (Bitbucket: amcnabb8, GitHub: Unknown) I am also experiencing this problem. I also tried adding the following lines to the run() method in the minimal working example posted by Ram: import coverage Unfortunately, this did not help. |
Original comment by amcnabb8 (Bitbucket: amcnabb8, GitHub: Unknown) Hmm. I don't have a very complete picture for how coveragepy works, but it looks like when multiple processes share a coverage file, each process clobbers the file when it writes. I had expected to see something like file locking to prevent race conditions, but it looks like this doesn't happen. One possible solution would be to have a .coverage directory (instead of a .coverage file), and to have each process write to its own file within the directory. The directory could be cleared as the main process starts, and reporting could combine the data from all of the files in the directory. |
Original comment by memedough (Bitbucket: memedough, GitHub: memedough) Hi, Multiprocessing uses fork, the child process has same coverage obj as parent so clobber. pytest-cov, nose-cov, nose2-cov use multiprocessing hook after fork to child start coverage with unique data file, also use multiprocessing finalizer to stop then write file. Use them to get multiprocessing coverage out of box. If coverage start doing multiprocessing then please let know so I make plugins works with changed coverage. Look at cov-core near top the file if you like. :) |
Original comment by Anton Löfgren (Bitbucket: cath, GitHub: cath) I'm experiencing some weirdness when running coverage.py on a test suite which uses multiprocessing.Process. Namely, it gets confused with regards to the tracer functions resulting in: Coverage.py warning: Trace function changed, measurement is likely wrong: <bound method PyTracer._trace of <coverage.collector.PyTracer object at 0x2b98b0626390>> Removing the call to threading.settrace() (in coverage.collector.Collector) seems to resolve the issue, though I'm not sure about the reliability of the coverage measurements reported. |
Anton: do you have a reproducible test case you could share? |
Original comment by Jan-Philip Gehrcke (Bitbucket: jgehrcke, GitHub: jgehrcke) You should look into http://pypi.python.org/pypi/nose-cov/ which supports tracking of code run in child processes spawned via multiprocessing or subprocess modules. |
Original comment by eduardo schettino (Bitbucket: schettino72, GitHub: schettino72) I solved this by monkey-patching the multiprocessing module. I wondering if this should be included in coverage, probably not by default but |
Issue #338 was marked as a duplicate of this issue. |
@schettino72 I couldn't get your monkey-patching code to work. Do you have a complete example? |
Original comment by eduardo schettino (Bitbucket: schettino72, GitHub: schettino72) Hi Ned. Thanks for looking into this. The patch I actually use is https://github.com/pydoit/doit/blob/master/tests/conftest.py#L146 I just tested with both pyhon 2.7 and 3.4 using coverage 3.7.1, |
@schettino72 Thanks, that works for me also, if I don't forget to use "coverage combine"! :) |
Original comment by Anonymous I found a hole in the patch while I was working with it. It worked quite well, but processes started under coverage typically didn't take a coveragerc file with them, especially a custom one without that name. This is the version I used;
Just a tiny improvement I thought I'd share with the community. Hope it helps. |
@mezarim thanks, can you explain it a little more? You are using an unusually-named configuration file? |
This monkeypatching is implemented in coverage.py as of f84263e515c2 (bb). I'll wait to close the issue until I can implement the config_file improvement also. |
Original comment by Pieter Rautenbach (Bitbucket: parautenbach, GitHub: parautenbach) I've experimented with this branch, and it works great. It would be great to see this incorporated into a stable (non-alpha) release, with a |
Original comment by Pieter Rautenbach (Bitbucket: parautenbach, GitHub: parautenbach) While experimenting with this patch, I was wondering whether the |
Original comment by hugovk (Bitbucket: hugovk, GitHub: hugovk) I'd like to start using nose's parallel testing to speed up Pillow's tests on Travis CI. It looks like the Currently it does something like this (using Coverage 3) (before some later processing to include C coverage, but let's ignore that for now).
To use nose's parallel testing, I added
Nose runs the tests in parallel, they take under 100 seconds instead of over 300 seconds. I'm sure those |
Issue #446 was marked as a duplicate of this issue. |
I'm going to mark this issue as fixed, now that 4.0 has |
Original comment by Andrey Cizov (Bitbucket: andreycizov, GitHub: andreycizov)
Here's the gist that fixes it: https://gist.github.com/andreycizov/ee59806a3ac6955c127e511c5e84d2b6 |
@andreycizov Would you mind opening a new issue, with details of the problem? A reproducible test case would be great, and also information about whether this was always a problem, or is it a regression? Thanks. |
This switches the curio backend to using the native task timeout mechanism.
Originally reported by Ram Rachum (Bitbucket: coolrr, GitHub: coolrr)
If you have a
multiprocessing.Process
that runs on some lines of code, Coverage currently doesn't detect that and doesn't mark these lines as executed.A sample module that uses
multiprocessing.Process
is attached; when run withcoverage
, all the1 + 1
lines are marked as not executed, when in fact they have been executed by the auxiliary process.The text was updated successfully, but these errors were encountered: