mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-21 14:42:19 +01:00
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Finish the queue left uncommitted on 2026-11-17: callers that find a scope taken get a ticket and are granted in arrival order, dead sessions are reaped at once. The CLI keeps exit 3 for a held scope. fix_waifu2x.sh patched the CUDA waifu2x build, now uninstalled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzxdWV2U9cEtTMTf7iQWin
82 lines
2.3 KiB
Python
82 lines
2.3 KiB
Python
"""One phone, many Claude sessions: leases that keep them from colliding.
|
|
|
|
Two sessions driving the same phone interleave their taps -- on 2026-09-20 a
|
|
tap meant for the workout sandbox landed in another session's manga reader,
|
|
twice. This package hands out *scoped* leases:
|
|
|
|
* the leases are one JSON file per serial under ``~/.cache/phone-lease/``,
|
|
guarded by ``flock`` so read-modify-write is atomic across processes;
|
|
* a lease covers one app (``--package``), the real screen (the default), or
|
|
the whole phone (``--whole-phone``: Doze, sleep, reboot -- capped at five
|
|
minutes, with cleanup commands a detached reaper runs if nobody releases);
|
|
* the owner is the nearest ancestor ``claude`` process (one per session);
|
|
* the serial is always resolved (:mod:`.serial`), never a placeholder, so
|
|
every caller agrees on which phone a lease is for;
|
|
* a lease expires ``ttl`` seconds after its last refresh;
|
|
* callers that find their scope taken wait in a fair FIFO queue: each gets a
|
|
ticket it keeps for :data:`TICKET_TTL` seconds after its last try, and
|
|
leases and tickets of sessions that died are dropped at once.
|
|
|
|
Sessions that drive apps on their own virtual display
|
|
(``~/.claude/scripts/phone_vd.sh``) need only a package lease, so several of
|
|
them can work on one phone at the same time.
|
|
"""
|
|
|
|
from python_pkg.phone_lease import _cleanup
|
|
from python_pkg.phone_lease.lease import (
|
|
DEFAULT_TTL,
|
|
DEFAULT_WAIT,
|
|
QUEUED_EXIT,
|
|
SCREEN,
|
|
TICKET_TTL,
|
|
WHOLE_PHONE,
|
|
WHOLE_PHONE_MAX_TTL,
|
|
Clock,
|
|
Lease,
|
|
PhoneBusyError,
|
|
PhoneQueuedError,
|
|
Terms,
|
|
Ticket,
|
|
acquire,
|
|
scope_of,
|
|
)
|
|
from python_pkg.phone_lease.ops import (
|
|
holds,
|
|
queue_of,
|
|
reap,
|
|
release,
|
|
status,
|
|
status_all,
|
|
)
|
|
from python_pkg.phone_lease.owner import owner_alive, owner_id
|
|
from python_pkg.phone_lease.serial import NoPhoneError, resolve_serial
|
|
|
|
__all__ = [
|
|
"DEFAULT_TTL",
|
|
"DEFAULT_WAIT",
|
|
"QUEUED_EXIT",
|
|
"SCREEN",
|
|
"TICKET_TTL",
|
|
"WHOLE_PHONE",
|
|
"WHOLE_PHONE_MAX_TTL",
|
|
"Clock",
|
|
"Lease",
|
|
"NoPhoneError",
|
|
"PhoneBusyError",
|
|
"PhoneQueuedError",
|
|
"Terms",
|
|
"Ticket",
|
|
"_cleanup",
|
|
"acquire",
|
|
"holds",
|
|
"owner_alive",
|
|
"owner_id",
|
|
"queue_of",
|
|
"reap",
|
|
"release",
|
|
"resolve_serial",
|
|
"scope_of",
|
|
"status",
|
|
"status_all",
|
|
]
|