Skip to content

Cothread generates segmentation faults when run with Coverage #73

Description

@AlexanderWells-diamond

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions