def async(proxy): pid = id(proxy) if pid in _async_proxies_cache: return _async_proxies_cache[pid] if not hasattr(proxy, "____conn__") or not hasattr(proxy, "____oid__"): raise TypeError("'proxy' must be a Netref: %r", (proxy,)) if not callable(proxy): raise TypeError("'proxy' must be callable: %r" % (proxy,)) caller = _Async(proxy) _async_proxies_cache[id(caller)] = _async_proxies_cache[pid] = caller return caller
def async_(proxy): """ Returns an asynchronous "version" of the given proxy. Invoking the returned proxy will not block; instead it will return an :class:`rpyc.core.async_.AsyncResult` object that you can test for completion :param proxy: any **callable** RPyC proxy :returns: the proxy, wrapped by an asynchronous wrapper Example:: async_sleep = rpyc.async_(conn.modules.time.sleep) res = async_sleep(5) .. _async_note: .. note:: In order to avoid overloading the GC, the returned asynchronous wrapper is cached as a weak reference. Therefore, do not use:: rpyc.async_(foo)(5) Always store the returned asynchronous wrapper in a variable, e.g. :: a_foo = rpyc.async_(foo) a_foo(5) .. note:: Furthermore, async requests provide **no guarantee on execution order**. In particular, multiple subsequent async requests may be executed in reverse order. """ pid = id(proxy) if pid in _async_proxies_cache: return _async_proxies_cache[pid] if not hasattr(proxy, "____conn__") or not hasattr(proxy, "____id_pack__"): raise TypeError("'proxy' must be a Netref: %r", (proxy, )) if not callable(proxy): raise TypeError("'proxy' must be callable: %r" % (proxy, )) caller = _Async(proxy) _async_proxies_cache[id(caller)] = _async_proxies_cache[pid] = caller return caller
def async (proxy): """ Returns an asynchronous "version" of the given proxy. Invoking the returned proxy will not block; instead it will return an :class:`rpyc.core.async.AsyncResult` object that you can test for completion :param proxy: any **callable** RPyC proxy :returns: the proxy, wrapped by an asynchronous wrapper Example:: async_sleep = rpyc.async(conn.modules.time.sleep) res = async_sleep(5) .. _async_note: .. note:: In order to avoid overloading the GC, the returned asynchronous wrapper is cached as a weak reference. Therefore, do not use:: rpyc.async(foo)(5) Always store the returned asynchronous wrapper in a variable, e.g. :: a_foo = rpyc.async(foo) a_foo(5) """ pid = id(proxy) if pid in _async_proxies_cache: return _async_proxies_cache[pid] if not callable(proxy): raise TypeError("'proxy' must be callable: %r" % (proxy, )) if hasattr(proxy, "____conn__") and hasattr(proxy, "____oid__"): caller = _Async(proxy) _async_proxies_cache[id(caller)] = _async_proxies_cache[pid] = caller elif hasattr(proxy, "__self__") and hasattr(proxy, "__name__") and hasattr( proxy.__self__, "____conn__") and hasattr(proxy.__self__, "____oid__"): caller = _AsyncMethod(proxy) else: caller = _DummyAsync(proxy) return caller
def async_(proxy): """ Returns an asynchronous "version" of the given proxy. Invoking the returned proxy will not block; instead it will return an :class:`rpyc.core.async_.AsyncResult` object that you can test for completion :param proxy: any **callable** RPyC proxy :returns: the proxy, wrapped by an asynchronous wrapper Example:: async_sleep = rpyc.async_(conn.modules.time.sleep) res = async_sleep(5) .. _async_note: .. note:: In order to avoid overloading the GC, the returned asynchronous wrapper is cached as a weak reference. Therefore, do not use:: rpyc.async_(foo)(5) Always store the returned asynchronous wrapper in a variable, e.g. :: a_foo = rpyc.async_(foo) a_foo(5) .. note:: Furthermore, async requests provide **no guarantee on execution order**. In particular, multiple subsequent async requests may be executed in reverse order. """ pid = id(proxy) if pid in _async_proxies_cache: return _async_proxies_cache[pid] if not hasattr(proxy, "____conn__") or not hasattr(proxy, "____oid__"): raise TypeError("'proxy' must be a Netref: %r", (proxy,)) if not callable(proxy): raise TypeError("'proxy' must be callable: %r" % (proxy,)) caller = _Async(proxy) _async_proxies_cache[id(caller)] = _async_proxies_cache[pid] = caller return caller