proxystore.store.scopes¶
Utilities for managing reference proxy scopes and lifetimes.
mark_refs_out_of_scope
¶
mark_refs_out_of_scope(
*refs: RefProxy[Any] | RefMutProxy[Any],
) -> None
Mark proxy references as out of scope.
This (1) decrements the reference count in the owner proxy, (2) marks the reference proxy invalid, and (3) removes the reference to the owner from the reference proxy so the reference proxy will not prevent the owned proxy from being garbage collected.
Parameters:
-
refs
(RefProxy[Any] | RefMutProxy[Any]
, default:()
) –Reference proxies to mark out of scope.
Raises:
-
RuntimeError
–if a reference proxy does not have a reference to its owner.
Source code in proxystore/store/scopes.py
submit
¶
submit(
submit_func: Callable[P, FutureT],
*,
args: args = (),
kwargs: kwargs | None = None,
register_custom_refs: Iterable[Any] = ()
) -> FutureT
Shim around function executor for managing reference proxy scopes.
When invoking a remote function, such as via a
ProcessPoolExecutor
or a FaaS system, on a proxy reference, the owner proxy will not know when
the proxy references go out of scope on the remote process. This function
will register a callback to the future returned by the function
invocation method (submit_func
) that will mark all proxy references in
args
and kwargs
as out of scope once the future completes.
Example
from concurrent.futures import Future
from concurrent.futures import ProcessPoolExecutor
from proxystore.store.base import Store
from proxystore.store.ref import borrow
store = Store('example', ...)
proxy = store.owned_proxy([1, 2, 3])
borrowed = borrow(proxy)
with ProcessPoolExecutor() as pool:
future: Future[int] = submit(pool.submit, args=(sum, borrowed))
assert future.result() == 6
store.close()
Tip
To return a proxy from the invoked function, return a normal
Proxy
and then call
into_owned()
on the received
result. Returning an OwnedProxy
directly will often not work because the owned proxy will go out of
scope when the function returns and the proxy is serialized causing
the destructor of the owned proxy to evict the associated data.
Parameters:
-
submit_func
(Callable[P, FutureT]
) –Function with submits a function with args and kwargs to be executed (e.g.,
Executor.submit()
). -
args
(args
, default:()
) –Positional arguments to pass to
submit_func
. Any proxy references inargs
will be registered to the scope cleanup callback. -
kwargs
(kwargs | None
, default:None
) –Keyword arguments to pass to
submit_func
. Any proxy references in the values ofkwargs
will be registered to the scope cleanup callback. -
register_custom_refs
(Iterable[Any]
, default:()
) –Iterable of additional proxy references to register to the scope cleanup callback. This is helpful if
args
orkwargs
contain complex data structures containing more proxy references.
Source code in proxystore/store/scopes.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|