Skip to content

Commit

Permalink
Fixes for aioca 1.8.* and general CI cleanup issue
Browse files Browse the repository at this point in the history
aioca 1.8 changed its atexit handling to work better with other EPICS
libraries. Note that cothread isn't quite so nice so there still needs
to be some accomodation for that.

Sometimes the CI would be unable to delete its temporary dir used for
test results, thus failing the build.
  • Loading branch information
AlexanderWells-diamond committed Nov 5, 2024
1 parent 35bb833 commit 7886f33
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
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
19 changes: 17 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@
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)
import cothread.catools

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

Expand Down Expand Up @@ -73,12 +83,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

0 comments on commit 7886f33

Please sign in to comment.