Skip to content

Commit 333fbfc

Browse files
Merge pull request #176 from DiamondLightSource/aioca_1.8_fixes
Fixes for aioca 1.8.*
2 parents 35bb833 + a4cb569 commit 333fbfc

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

.github/workflows/code.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ jobs:
9595
env:
9696
CIBW_BUILD: ${{ matrix.python }}*64
9797
CIBW_TEST_EXTRAS: dev
98-
CIBW_TEST_COMMAND: pytest {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }}
98+
# Added a sleep command afterwards to let all cleanup finish; sometimes
99+
# cibuildwheel reports it cannot clean up the temp dir used for testing,
100+
# and fails the build. Sleeping seems to give pytest enough time to
101+
# fully clean up.
102+
CIBW_TEST_COMMAND: pytest {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }} && sleep 2
99103
# Run with faulthandler and -s in the hope we get a stack trace on seg fault on windows...
100104
CIBW_TEST_COMMAND_WINDOWS: python -X faulthandler -m pytest -s {project}/tests --cov-report xml:${{ matrix.cov_file }} --junit-xml=${{ matrix.results_file }}
101105
# Disable auditwheel as it isn't compatible with setuptools_dso approach

tests/conftest.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@
66
import string
77
import subprocess
88
import sys
9+
from packaging.version import Version
910
from typing import Any
1011
import pytest
1112

13+
# It is necessary to ensure we always import cothread.catools before aioca as
14+
# doing this import will cause an EPICS context to be created, and it will also
15+
# register an atexit function to delete it.
16+
# If we were to import aioca first it would create an EPICS context, note it has
17+
# created it, then try to delete it in its own atexit function which will
18+
# collide with cothread's attempts to do the same (despite the fact in this
19+
# configuration cothread did not create the context)
20+
if os.name != "nt":
21+
import cothread.catools
22+
1223
from softioc import builder
1324
from softioc.builder import ClearRecords, SetDeviceName, GetRecordNames
1425

@@ -73,12 +84,17 @@ def cothread_ioc():
7384

7485

7586
def aioca_cleanup():
76-
from aioca import purge_channel_caches, _catools
87+
from aioca import purge_channel_caches, _catools, __version__
7788
# Unregister the aioca atexit handler as it conflicts with the one installed
7889
# by cothread. If we don't do this we get a seg fault. This is not a problem
7990
# in production as we won't mix aioca and cothread, but we do mix them in
8091
# the tests so need to do this.
81-
atexit.unregister(_catools._Context._destroy_context)
92+
# In aioca 1.8 the atexit function was changed to no longer cause this
93+
# issue, when coupled with ensuring cothread is always imported first.
94+
if Version(__version__) < Version("1.8"):
95+
unregister_func = _catools._Context._destroy_context
96+
atexit.unregister(unregister_func)
97+
8298
# purge the channels before the event loop goes
8399
purge_channel_caches()
84100

0 commit comments

Comments
 (0)