Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions slac_timing/buffer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gc
import time as _time
from abc import ABC, abstractmethod
from typing import Optional
Expand Down Expand Up @@ -73,7 +72,27 @@ def _disconnect_pvs(self) -> None:
if self._pvs is not None:
self._pvs.disconnect()
self._pvs = None
gc.collect() # Force garbage collection to clean up PVs
self._clear_ca_cache()

def _clear_ca_cache(self) -> None:
"""Remove caget-created channels for this buffer from the CA cache."""
import epics.ca

ctx = epics.ca.current_context()
if ctx is None:
return
context_cache = epics.ca._cache.get(ctx)
if context_cache is None:
return
suffix = f"HST{self.number}"
stale = [name for name in context_cache if name.endswith(suffix)]
for name in stale:
entry = context_cache.pop(name, None)
if entry is not None and entry.chid is not None:
try:
epics.ca.clear_channel(entry.chid)
except Exception:
pass

def is_reserved(self) -> bool:
return self.number is not None and self.number != 0
Expand Down
Loading