Skip to content

Commit

Permalink
Merge pull request #176 from DiamondLightSource/aioca_1.8_fixes
Browse files Browse the repository at this point in the history
Fixes for aioca 1.8.*
  • Loading branch information
AlexanderWells-diamond authored Nov 5, 2024
2 parents 35bb833 + a4cb569 commit 333fbfc
Show file tree
Hide file tree
Showing 2 changed files with 23 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
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

0 comments on commit 333fbfc

Please sign in to comment.