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