Skip to main content

Status Polling

Several methods include an optional argument for status polling, called handle_status_poll (or handle_dataset_upload_status_poll and handle_forecast_status_poll for the clean_forecast method). This optional argument supports the use of a callback function for polling for status and progress of longer running methods, ex.g. when executing a job or uploading a dataset. This section illustrates how such an argument can be used to retrieve status updates and get additional insight into the progress of the method.

In the following examples, the method a_TIM_method represents any method on the TIM Python client that includes a parameter for status polling, and **arguments represents all other arguments (other than the callback function) passed to that method.

In the code examples below, a list is initialized that is meant to contain all status updates. Then, a lambda function is created to push new updates to this list. This function is then passed to the TIM method as the argument for the handle_status_poll parameter.

With keyword arguments:

statuses: List[StatusResponse] = list()
push_status = lambda status: statuses.append(status)
client.a_TIM_method(**arguments, handle_status_poll = push_status)

With positional arguments:

statuses: List[StatusResponse] = list()
push_status = lambda status: statuses.append(status)
client.a_TIM_method(**arguments, push_status)

The next code examples pass the built-in Python print function, that will print new updates, to the TIM method as the argument for the handle_status_poll parameter.

With keyword arguments:

client.a_TIM_method(**arguments, handle_status_poll = print)

With positional arguments:

client.a_TIM_method(**arguments, print)