tay-client 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tay/__init__.py ADDED
@@ -0,0 +1,35 @@
1
+ """Public Python SDK for the Tay Protocol v1 local executor endpoint."""
2
+
3
+ from .client import JobHandle, ScheduleHandle, Tay
4
+ from .errors import (
5
+ ConnectionLost,
6
+ ModeError,
7
+ ProtocolError,
8
+ RemoteTaskError,
9
+ ResultTooLarge,
10
+ ServerError,
11
+ TaskNotRegistered,
12
+ TaskRegistrationError,
13
+ TayError,
14
+ ValidationError,
15
+ )
16
+ from .socket_path import resolve_socket_path
17
+ from .task import Task
18
+
19
+ __all__ = [
20
+ "ConnectionLost",
21
+ "JobHandle",
22
+ "ModeError",
23
+ "ProtocolError",
24
+ "RemoteTaskError",
25
+ "ResultTooLarge",
26
+ "ScheduleHandle",
27
+ "ServerError",
28
+ "Task",
29
+ "TaskNotRegistered",
30
+ "TaskRegistrationError",
31
+ "Tay",
32
+ "TayError",
33
+ "ValidationError",
34
+ "resolve_socket_path",
35
+ ]
tay/__main__.py ADDED
@@ -0,0 +1,67 @@
1
+ """The small, dependency-free dedicated-worker entry point."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import asyncio
7
+ import importlib
8
+ import signal
9
+ import sys
10
+ from typing import Any
11
+
12
+ from .client import Tay
13
+
14
+
15
+ def _instance(specification: str) -> Tay:
16
+ module_name, separator, attribute = specification.partition(":")
17
+ module = importlib.import_module(module_name)
18
+ if separator:
19
+ candidate: Any = getattr(module, attribute)
20
+ if not isinstance(candidate, Tay):
21
+ raise TypeError(f"{specification!r} is not a Tay instance")
22
+ return candidate
23
+
24
+ candidates = tuple(
25
+ instance for instance in Tay.instances() if instance.__module__ == "tay.client"
26
+ )
27
+ if len(candidates) != 1:
28
+ raise RuntimeError(
29
+ f"{module_name!r} must create exactly one Tay instance, or use module:attribute"
30
+ )
31
+ return candidates[0]
32
+
33
+
34
+ async def _serve(instance: Tay) -> None:
35
+ if instance.mode != "worker":
36
+ raise RuntimeError("tay-worker requires Tay(mode='worker')")
37
+
38
+ stopped = asyncio.Event()
39
+ loop = asyncio.get_running_loop()
40
+ for current in (signal.SIGINT, signal.SIGTERM):
41
+ try:
42
+ loop.add_signal_handler(current, stopped.set)
43
+ except (
44
+ NotImplementedError
45
+ ): # pragma: no cover - Windows has no UDS support here
46
+ pass
47
+
48
+ await instance.start()
49
+ try:
50
+ await stopped.wait()
51
+ finally:
52
+ await instance.close()
53
+
54
+
55
+ def main(argv: list[str] | None = None) -> int:
56
+ parser = argparse.ArgumentParser(description="run a dedicated Tay Python worker")
57
+ parser.add_argument("application", help="module or module:Tay_instance to import")
58
+ arguments = parser.parse_args(argv)
59
+ try:
60
+ asyncio.run(_serve(_instance(arguments.application)))
61
+ except (ImportError, AttributeError, RuntimeError, TypeError) as exc:
62
+ parser.error(str(exc))
63
+ return 0
64
+
65
+
66
+ if __name__ == "__main__": # pragma: no cover
67
+ sys.exit(main())