Skip to content

Coverage after fork seems not to be generated #1941

@MarkSymsCtx

Description

@MarkSymsCtx

Describe the bug
If a python process uses os.fork it seems that even with concurreny=multiprocessing no coverage of the child process is generated. Example file below

To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:

  1. What version of Python are you using?
    3.11
  2. What version of coverage.py shows the problem? The output of coverage debug sys is helpful.
    7.6.12
  3. What code shows the problem?
    This (not the nicest as it's just a quick hack to replicate some of our code)
#!/usr/bin/python3

import os
import tempfile
import time
import traceback

COMPLETE=tempfile.mkstemp()

print(f"Parent pid is {os.getpid()}")

pid = os.fork()
if pid:
    print(f"In parent, child is {pid}")
    try:
        while True:
            with open(COMPLETE[1], mode='r') as f:
                data = f.readline()

            print(f"Data is {data}")
            if "Complete" in data:
                print(f"Child is complete")
                break

            time.sleep(5)
    finally:
        wait_pid = 0
        while wait_pid == 0:
            wait_pid, rc = os.waitpid(pid, os.WNOHANG)
            if wait_pid == 0:
                time.sleep(2)
else:
    print(f"In child")
    time.sleep(10)
    print("Leaving child")
    with open(COMPLETE[1], mode='w') as f:
        f.write("Complete")
    os._exit(0)

Then run with coverage run -p --concurrency=multiprocessing test-fork-cover.py

Expected behavior
Expect to see coverage of both sides of the fork

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingduplicateThis issue or pull request already exists

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy