DiamondLightSource / DiamondLightSource/cothread

Cothread generates segmentation faults when run with Coverage

Open
#73 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C
Stars
13
Forks
11
PR merge metrics
No merged PRs in 30d

Description

In Python3.11+, it seems that Cothread is incompatible with Coverage. Attempting to run it will cause a segmentation fault during Pytest's cleanup stage, presumably at the stage when Coverage is doing its processing.

To recreate, create a Python3.11 virtual environment and add this program to the `tests/` directory, named `test_crash.py` or simiar.

```
import cothread

def tick():
print("Test tick print!")

def tock():
print("Test tock print!")

def test_stuff():
t = cothread.Timer(0.1, tick)

cothread.Spawn(tock).Wait()

if __name__ == "__main__":
test_stuff()
```

Then run `pytest -s --cov=cothread --cov-report term --cov-report xml:cov.xml tests/test_crash.py`. You will see something similar to this:

```
$ pytest -s --cov=cothread --cov-rep
ort term --cov-report xml:cov.xml tests/test_crash.py
======================== test session starts ========================
platform linux -- Python 3.12.8, pytest-8.3.5, pluggy-1.5.0 -- /scratch/eyh46967/dev/cothread/venv/bin/python3.12
cachedir: .pytest_cache
rootdir: /scratch/eyh46967/dev/cothread
configfile: pyproject.toml
plugins: cov-6.1.1, anyio-4.9.0
collected 1 item

tests/test_crash.py::test_stuff Test tock print!
PASSEDFatal Python error: Segmentation fault

Thread 0x00007fbf91d02740 (most recent call first):

Thread 0x00007fbf91d02740 (most recent call first):
File Segmentation fault (core dumped)
```

A small amount of extra information can be gleaned from running the test under Valgrind: `valgrind pytest -s --cov=cothread --cov-report term --cov-report xml:cov.xml tests/test_crash.py`. See attached file.

[valgrind_output.txt](https://github.com/user-attachments/files/20255901/valgrind_output.txt)

At this time it is unknown if this is the only incompatibility with Cothread; it is possible other programs that do similar interactions with the various `PyThread_*` API calls will also suffer from issues or not.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.