|
6 | 6 | import string
|
7 | 7 | import subprocess
|
8 | 8 | import sys
|
| 9 | +from packaging.version import Version |
9 | 10 | from typing import Any
|
10 | 11 | import pytest
|
11 | 12 |
|
| 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 | + |
12 | 23 | from softioc import builder
|
13 | 24 | from softioc.builder import ClearRecords, SetDeviceName, GetRecordNames
|
14 | 25 |
|
@@ -73,12 +84,17 @@ def cothread_ioc():
|
73 | 84 |
|
74 | 85 |
|
75 | 86 | def aioca_cleanup():
|
76 |
| - from aioca import purge_channel_caches, _catools |
| 87 | + from aioca import purge_channel_caches, _catools, __version__ |
77 | 88 | # Unregister the aioca atexit handler as it conflicts with the one installed
|
78 | 89 | # by cothread. If we don't do this we get a seg fault. This is not a problem
|
79 | 90 | # in production as we won't mix aioca and cothread, but we do mix them in
|
80 | 91 | # 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 | + |
82 | 98 | # purge the channels before the event loop goes
|
83 | 99 | purge_channel_caches()
|
84 | 100 |
|
|
0 commit comments