Skip to content

Coverage fails with os.fork and os._exit #310

Closed
@nedbat

Description

@nedbat

Originally reported by Marc Schlaich (Bitbucket: schlamar, GitHub: schlamar)


It is a common pattern to exit a child process with os._exit after a fork (ref). However, in this case coverage for the child process fails.

Example:

import os

def child():
    a = 1 + 1
    assert a == 2


def main():
    pid = os.fork()
    if pid:
        _, systemstatus = os.waitpid(pid, 0)
        assert not systemstatus
    else:
        child()
        os._exit(0)


if __name__ == '__main__':
    main()

Test run:

$ coverage run -p cov.py
$ coverage combine && coverage report -m
Name    Stmts   Miss  Cover   Missing
-------------------------------------
cov        13      4    69%   6-7, 16-17

Metadata

Metadata

Assignees

No one assigned

    Labels

    exoticUnusual execution environmentfixed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions