You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any function that takes performs batching on results and automatically aggregates them (i.e., one that takes the container_size parameter) could benefit from firing a caller-specified callback function, which can be used for example to display progress updates to the user. This is particularly useful for calling e.g. section.searchTracks() and similar, which could potentially return many thousands of results.
Are there any workarounds?
None that I'm aware of.
Code Snippets
defshow_progress(n_received: int: n_total: Optional[int]) ->None:
# Note: `n_total` may not always be available (sometimes `None`)print(f"Received {n_received} / {n_total} items so far")
section.searchTracks(batch_callback=show_progress)
Additional Context
No response
The text was updated successfully, but these errors were encountered:
those are just wrappers around fetchItems, which you can call over a loop and show progress.
you can derive from below according to your need. I wrote this to iterate lazily instead of letting it load all at once, you can put you show progress before each yield. with #1373 you can access total items as MediaContainer.totalSize so update you version accordingly.
fromtypingimportAny, Callable, Iterator, TypeVarfromplexapi.exceptionsimportPlexApiExceptionT=TypeVar("T")
defplex_batch_iterator(
func: Callable[..., list[T]], batch_size: int=50, **kwargs: Any
) ->Iterator[T]:
"""call api in batches and yield results"""container_start=0container_size=batch_sizewhileTrue:
try:
container=func(
container_start=container_start,
maxresults=container_size,
**kwargs,
)
ifnotcontainer:
breakcontainer_start+=container_sizeyieldfromcontainerexceptPlexApiException:
break
What is your feature request?
Any function that takes performs batching on results and automatically aggregates them (i.e., one that takes the
container_size
parameter) could benefit from firing a caller-specified callback function, which can be used for example to display progress updates to the user. This is particularly useful for calling e.g.section.searchTracks()
and similar, which could potentially return many thousands of results.Are there any workarounds?
None that I'm aware of.
Code Snippets
Additional Context
No response
The text was updated successfully, but these errors were encountered: