diff --git a/piker/data/_sharedmem.py b/piker/data/_sharedmem.py index 0a797600..acb8070f 100644 --- a/piker/data/_sharedmem.py +++ b/piker/data/_sharedmem.py @@ -520,9 +520,12 @@ def open_shm_array( # "unlink" created shm on process teardown by # pushing teardown calls onto actor context stack - stack = tractor.current_actor().lifetime_stack - stack.callback(shmarr.close) - stack.callback(shmarr.destroy) + stack = tractor.current_actor( + err_on_no_runtime=False, + ).lifetime_stack + if stack: + stack.callback(shmarr.close) + stack.callback(shmarr.destroy) return shmarr @@ -607,7 +610,10 @@ def attach_shm_array( _known_tokens[key] = token # "close" attached shm on actor teardown - tractor.current_actor().lifetime_stack.callback(sha.close) + if (actor := tractor.current_actor( + err_on_no_runtime=False, + )): + actor.lifetime_stack.callback(sha.close) return sha