omero.callbacks module

Callbacks to be used with asynchronous services. The ProcessCallbackI is also included in the omero.scripts module for backwards compatibility.

class callbacks.CmdCallbackI(*args: Any, **kwargs: Any)[source]

Bases: CmdCallback

Callback servant used to wait until a HandlePrx would return non-null on getReponse. The server will notify of completion to prevent constantly polling on getResponse. Subclasses can override methods for handling based on the completion status.

Example usage:

cb = CmdCallbackI(client, handle)
response = None
while (response is None):
    response = cb.block(500)

# or

response = cb.loop(5, 500)
block(ms)[source]

Blocks for the given number of milliseconds unless finished(Response, Status, Current) has been called in which case it returns immediately with true. If false is returned, then the timeout was reached.

close(closeHandle)[source]

First removes self from the adapter so as to no longer receive notifications, and the calls close on the remote handle if requested.

finished(rsp, status, current=None)[source]

Called when the command has completed whether with a cancellation or a completion.

getResponse()[source]

Returns possibly null Response value. If null, then neither has the remote server nor the local poll method called finish with non-null values.

getStatus()[source]

Returns possibly null Status value. If null, then neither has the remote server nor the local poll method called finish with non-null values.

getStatusOrThrow()[source]
initialPoll(foreground_poll=False)[source]

Called at the end of construction to check a race condition.

If HandlePrx finishes its execution before the CmdCallbackPrx has been sent set via addCallback, then there’s a chance that this implementation will never receive a call to finished, leading to perceived hangs.

By default, this method starts a background thread and calls poll(). An Ice.ObjectNotExistException implies that another caller has already closed the HandlePrx. By passing, foreground_poll=True, the poll() invocation can be performed in the calling thread as in 5.1.0 and before.

isCancelled()[source]

Returns whether Status::CANCELLED is contained in the flags variable of the Status instance. If no Status is available, a ClientError will be thrown.

isFailure()[source]

Returns whether Status::FAILURE is contained in the flags variable of the Status instance. If no Status is available, a ClientError will be thrown.

loop(loops, ms)[source]

Calls block(long) “loops” number of times with the “ms” argument. This means the total wait time for the delete to occur is: loops X ms. Sensible values might be 10 loops for 500 ms, or 5 seconds.

@param loops Number of times to call block(long) @param ms Number of milliseconds to pass to block(long @throws omero.LockTimeout if block(long) does not return a non-null value after loops calls.

onFinished(rsp, status, current)[source]

Method intended to be overridden by subclasses. Default logic does nothing.

poll()[source]

Calls HandlePrx#getResponse in order to check for a non-null value. If so, {@link Handle#getStatus} is also called, and the two non-null values are passed to finished(Response, Status, Current). This should typically not be used. Instead, favor the use of block and loop.

step(complete, total, current=None)[source]

Called periodically by the server to signal that processing is moving forward. Default implementation does nothing.

class callbacks.ProcessCallbackI(*args: Any, **kwargs: Any)[source]

Bases: ProcessCallback

Simple callback which registers itself with the given process.

CANCELLED = 'CANCELLED'
FINISHED = 'FINISHED'
KILLED = 'KILLED'
block(ms)[source]

Should only be used if the default logic of the process methods is kept in place. If “event.set” does not get called, this method will always block for the given milliseconds.

close()[source]
processCancelled(success, current=None)[source]
processFinished(returncode, current=None)[source]
processKilled(success, current=None)[source]
callbacks.adapter_and_category(adapter_or_client, category)[source]