ThreadService
from skipcheck_tm1.services import ThreadService Server threads: what the server is doing right now (/Threads), and cancelling
an operation, which is how to stop a running process: cancelling a client's request
doesn't.
See what the server is busy with:
# What the server is doing now: every thread that isn't idle
not_idle = ODataQuery.none().select(Thread.ID, Thread.NAME, Thread.FUNCTION, Thread.ELAPSED_TIME).filter(Thread.STATE.ne("Idle"))
return [f"{thread.name}: {thread.function} for {thread.elapsed_time}" for thread in tm1.threads.list(not_idle)]
Stop a running process by cancelling its thread, found by its request:
# A process run through REST shows as its request, not by its name
running = ODataQuery.none().select(Thread.ID).filter(Filter.contains(Thread.FUNCTION, "Processes('Sales.Load')/tm1.ExecuteWithReturn"))
for thread in tm1.threads.list(running):
if thread.id is not None:
tm1.threads.cancel(thread.id)
The asyncio flavor, skipcheck_tm1.aio, has the same methods to await, on AsyncThreadService.
Members
list | GET Threads. |
get | The thread, or a Tm1NotFoundError if it's gone. |
session | The thread's session. |
cancel | Asks the thread to stop what it's doing, such as a running process; returns when the request is made, and the thread stops soon after. |
list
list(query: ODataQuery | None = None, **options: Any) -> list[Thread]GET Threads. A process run through REST shows as its request: Function is POST /api/v1/Processes('name')/tm1.ExecuteWithReturn, and TM1 (11.8) leaves ObjectName empty.
TM1 REST EntitySet Threads
get
get(id: int, query: ODataQuery | None = None, **options: Any) -> ThreadGET Threads(id): the thread, or a Tm1NotFoundError if it's gone.
TM1 REST EntitySet Threads
session
session(id: int, query: ODataQuery | None = None, **options: Any) -> SessionGET Threads(id)/Session: the thread's session. (This is Java's session(id); the service's own session is _session.)
TM1 REST Navigation Thread/Session
cancel
cancel(id: int) -> Nonetm1.CancelOperation: asks the thread to stop what it's doing, such as a running process; returns when the request is made, and the thread stops soon after. TM1 (11.8) then fails the process's ExecuteWithReturn request with 500, TM1UserException: Cancel (code 174), rather than reporting it Aborted. Needs schema 10.2.2.1.
TM1 REST Action Thread/CancelOperation