Cothread generates segmentation faults when run with Coverage

Open
#73 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, python

Research direction

Start by reproducing the crash with tests/test_crash.py using the documented pytest and coverage command under Python 3.11 or newer. Then inspect Cothread's PyThread_* API interactions and compare the failure with the attached Valgrind output. Done means the reproduction completes under coverage without a segmentation fault and related thread interactions are checked for regressions.

Written by the indexing model from the issue text.

Description

bug

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):
  <no Python frame>

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

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.

Dominant language
C
Stars
13
Forks
11
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DiamondLightSource/cothread

All issues in DiamondLightSource/cothread

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.