question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

asyncio.ProcessPoolExecutor tracing not working correctly

See original GitHub issue

Originally reported by Alexander Mohr (Bitbucket: thehesiod, GitHub: thehesiod)


first I had to monkey patch concurrent.futures.process._process_worker from concurrent.futures.ProcessPoolExecutor because it doesn’t call the atexit handlers:

#!python

def _concurrent_futures_process_worker(*args, **kwargs):
    orig_call = kwargs.pop('_orig_call')
    result = orig_call(*args, **kwargs)

    for aeh in _concurrent_futures_process_worker._atexit_handlers:
        aeh()

    return result

_concurrent_futures_process_worker._atexit_handlers = []

def _init_coverage_monkey_patch():
    try:
        import coverage
        cps = os.environ.get("COVERAGE_PROCESS_START")
        if not cps:
            return

        # process pool executors don't call atexit handlers :(
        concurrent.futures.process._process_worker = functools.partial(_concurrent_futures_process_worker, _orig_call=concurrent.futures.process._process_worker)
    except:
        pass

def start_coverage():
    try:
       import coverage

        cps = os.environ.get("COVERAGE_PROCESS_START")
        if not cps:
            # No request for coverage, nothing to do.
            return

        cov = coverage.Coverage(config_file=cps, auto_data=True)
        cov.start()
        cov._warn_no_data = False
        cov._warn_unimported_source = False

        _concurrent_futures_process_worker._atexit_handlers.append(cov._atexit)
    except:
        pass

my first note is that this monkey patch would be a lot simpler if coverage.process_startup() returned the Coverage instance.

With the above patching, and running with “-p” for parallel, I actually get coverage data, however it’s all bizarre. For example: in a function it will say the first line executed, but the next line did not, and the loop.run_until_complete line did not execute, but most of the lines in the coroutine did.


Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nedbatcommented, Jun 23, 2018

Thanks, I’m looking into this. BTW, I took your suggestion of returning the Coverage instance from process_startup. That’s in f3b4faef8280 (bb).

0reactions
nedbatcommented, Jun 23, 2018

Can you provide a reproducible description of the problem before we jump into the solution?

Read more comments on GitHub >

github_iconTop Results From Across the Web

7 ProcessPoolExecutor Common Errors in Python
Forgetting the main function will result in an error that can be ... it will look like your program is not working correctly,...
Read more >
The magic of asyncio explained | Hacker News
This architecture is made to match software threads to (logical) hardware threads, then have them loop over data separated into chunks that don' ......
Read more >
Asyncio with ProcessPoolExecutor shutdown before finishing ...
Windows Solution. If you are running on Windows then CTRL-C interrupt handling does not seem to work too well with multiprocessing pools.
Read more >
Misc/HISTORY - external/github.com/python/cpython
Issue #20456: Cloned functions in Argument Clinic now use the correct. name, not the name of the function they were cloned from, for...
Read more >
concurrent.futures.process.ProcessPoolExecutor Example
Learn how to use python api concurrent.futures.process. ... _opts and .name were not unpickled' bt.plot(results=stats, resample='2d', open_browser=False) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found