Clear CA cache to fix intermittent PV get failure
After some discussion, we realised that the problem was that the pyepics library caches PVs in the background to improve performance. However, this has the side-effect that when we run two IOCs back to back and query the same PV, the second fetch tries to fetch the old PV, which can fail. A simple example:
from epics import PV
from run_iocsh import IOC
iocsh_path = "/epics/base-7.0.5/require/3.4.1/bin/iocsh.bash"
with IOC("t.cmd",ioc_executable=iocsh_path) as ioc:
p = PV("s")
p.get(timeout=1)
print(p.timestamp)
with IOC("t.cmd",ioc_executable=iocsh_path) as ioc:
p = PV("s")
p.get(timeout=1)
print(p.timestamp)
The second timestamp is None
, since the pyepics library is still trying to fetch from the first IOC.
The solution is to clear the pyepics.ca
cache with a call to pyepics.ca.clear_cache()
which we can run at the end of each test fixture.