mirror of https://github.com/skygpu/skynet.git
Switch failable to use outcome
parent
eee19f1953
commit
36cb7b758a
|
@ -19,6 +19,7 @@ dependencies = [
|
|||
"zstandard>=0.23.0,<0.24",
|
||||
"click>=8.1.8,<9",
|
||||
"httpx>=0.28.1,<0.29",
|
||||
"outcome>=1.3.0.post0",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
|
|
@ -12,6 +12,7 @@ import trio
|
|||
import leap
|
||||
import anyio
|
||||
import httpx
|
||||
import outcome
|
||||
|
||||
from PIL import (
|
||||
Image,
|
||||
|
@ -36,25 +37,24 @@ from skynet.ipfs import (
|
|||
REQUEST_UPDATE_TIME: int = 3
|
||||
|
||||
|
||||
# TODO, consider using the `outcome` lib instead?
|
||||
# - it's already purpose built for exactly this, boxing (async)
|
||||
# function invocations..
|
||||
# |_ https://outcome.readthedocs.io/en/latest/api.html#outcome.capture
|
||||
async def failable(
|
||||
fn: partial,
|
||||
ret_fail=None,
|
||||
):
|
||||
try:
|
||||
return await fn()
|
||||
except (
|
||||
OSError,
|
||||
json.JSONDecodeError,
|
||||
anyio.BrokenResourceError,
|
||||
httpx.ReadError,
|
||||
leap.errors.TransactionPushError
|
||||
):
|
||||
async def failable(fn: partial, ret_fail=None):
|
||||
o = await outcome.acapture(fn)
|
||||
match o:
|
||||
case outcome.Error(error=(
|
||||
OSError() |
|
||||
json.JSONDecodeError() |
|
||||
anyio.BrokenResourceError() |
|
||||
httpx.ConnectError() |
|
||||
httpx.ConnectTimeout() |
|
||||
httpx.ReadError() |
|
||||
httpx.ReadTimeout() |
|
||||
leap.errors.TransactionPushError()
|
||||
)):
|
||||
return ret_fail
|
||||
|
||||
case _:
|
||||
return o.unwrap()
|
||||
|
||||
|
||||
# TODO, again the prefix XD
|
||||
# -[ ] better name then `GPUConnector` ??
|
||||
|
|
2
uv.lock
2
uv.lock
|
@ -2232,6 +2232,7 @@ dependencies = [
|
|||
{ name = "httpx" },
|
||||
{ name = "msgspec" },
|
||||
{ name = "numpy" },
|
||||
{ name = "outcome" },
|
||||
{ name = "pillow" },
|
||||
{ name = "protobuf" },
|
||||
{ name = "py-leap" },
|
||||
|
@ -2282,6 +2283,7 @@ requires-dist = [
|
|||
{ name = "httpx", specifier = ">=0.28.1,<0.29" },
|
||||
{ name = "msgspec", specifier = ">=0.19.0,<0.20" },
|
||||
{ name = "numpy", specifier = "<2.1" },
|
||||
{ name = "outcome", specifier = ">=1.3.0.post0" },
|
||||
{ name = "pillow", specifier = ">=10.0.1,<11" },
|
||||
{ name = "protobuf", specifier = ">=5.29.3,<6" },
|
||||
{ name = "py-leap", git = "https://github.com/guilledk/py-leap.git?rev=v0.1a32" },
|
||||
|
|
Loading…
Reference in New Issue