-
-
Notifications
You must be signed in to change notification settings - Fork 452
Closed as duplicate of#310
Labels
bugSomething isn't workingSomething isn't workingduplicateThis issue or pull request already existsThis issue or pull request already exists
Description
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:
- What version of Python are you using?
3.11 - What version of coverage.py shows the problem? The output of
coverage debug sys
is helpful.
7.6.12 - 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
Labels
bugSomething isn't workingSomething isn't workingduplicateThis issue or pull request already existsThis issue or pull request already exists