Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for aioca 1.8.* #176

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ jobs:
env:
CIBW_BUILD: ${{ matrix.python }}*64
CIBW_TEST_EXTRAS: dev
CIBW_TEST_COMMAND: pytest {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }}
# Added a sleep command afterwards to let all cleanup finish; sometimes
# cibuildwheel reports it cannot clean up the temp dir used for testing,
# and fails the build. Sleeping seems to give pytest enough time to
# fully clean up.
CIBW_TEST_COMMAND: pytest {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }} && sleep 2
# Run with faulthandler and -s in the hope we get a stack trace on seg fault on windows...
CIBW_TEST_COMMAND_WINDOWS: python -X faulthandler -m pytest -s {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }}
# Disable auditwheel as it isn't compatible with setuptools_dso approach
Expand Down
20 changes: 18 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@
import string
import subprocess
import sys
from packaging.version import Version
from typing import Any
import pytest

# It is necessary to ensure we always import cothread.catools before aioca as
# doing this import will cause an EPICS context to be created, and it will also
# register an atexit function to delete it.
# If we were to import aioca first it would create an EPICS context, note it has
# created it, then try to delete it in its own atexit function which will
# collide with cothread's attempts to do the same (despite the fact in this
# configuration cothread did not create the context)
if os.name != "nt":
import cothread.catools

from softioc import builder
from softioc.builder import ClearRecords, SetDeviceName, GetRecordNames

Expand Down Expand Up @@ -73,12 +84,17 @@ def cothread_ioc():


def aioca_cleanup():
from aioca import purge_channel_caches, _catools
from aioca import purge_channel_caches, _catools, __version__
# Unregister the aioca atexit handler as it conflicts with the one installed
# by cothread. If we don't do this we get a seg fault. This is not a problem
# in production as we won't mix aioca and cothread, but we do mix them in
# the tests so need to do this.
atexit.unregister(_catools._Context._destroy_context)
# In aioca 1.8 the atexit function was changed to no longer cause this
# issue, when coupled with ensuring cothread is always imported first.
if Version(__version__) < Version("1.8"):
unregister_func = _catools._Context._destroy_context
atexit.unregister(unregister_func)

# purge the channels before the event loop goes
purge_channel_caches()

Expand Down
Loading