nvflare.fuel.f3.streaming.stream_types module

class ObjectIterator(headers: dict | None = None)[source]

Bases: Iterator, ABC

An object iterator that returns next object The __next__() method must be defined to return next object.

get_headers() dict | None[source]
get_index() int[source]
set_index(index: int)[source]
stream_id() int[source]
class ObjectStreamFuture(stream_id: int, headers: dict | None = None)[source]

Bases: StreamFuture

get_index() int[source]

Current object index, which is only available for ObjectStream

get_progress()[source]
set_index(index: int)[source]

Set current object index

class Stream(size: int = 0, headers: dict | None = None)[source]

Bases: ABC

A raw, read-only, seekable binary byte stream

Constructor for stream

Parameters:
  • size – The total size of stream. 0 if unknown

  • headers – Optional headers to be passed to the receiver

close()[source]

Close the stream

get_headers() dict | None[source]
get_pos()[source]
get_size() int[source]
abstract read(chunk_size: int) bytes | bytearray | memoryview | list[source]

Read and return up to chunk_size bytes. It can return less but not more than the chunk_size. An empty bytes object is returned if the stream reaches the end.

Parameters:

chunk_size – Up to (but maybe less) this many bytes will be returned

Returns:

Binary data. If empty, it means the stream is depleted (EOF)

seek(offset: int)[source]

Change the stream position to the given byte offset. :param offset: Offset relative to the start of the stream

Exception:

StreamError: If the stream is not seekable

exception StreamCancelled[source]

Bases: StreamError

Streaming is cancelled by sender

exception StreamError[source]

Bases: Exception

All stream API throws this error

class StreamFuture(stream_id: int, headers: dict | None = None)[source]

Bases: object

Future class for all stream calls.

Fashioned after concurrent.futures.Future

add_done_callback(done_cb: Callable, *args, **kwargs)[source]

Attaches a callable that will be called when the future finishes.

Parameters:

done_cb – A callable that will be called with this future completes

cancel()[source]

Cancel the future if possible.

Returns True if the future was cancelled, False otherwise. A future cannot be cancelled if it is running or has already completed.

cancelled()[source]
done()[source]

Return True of the future was cancelled or finished executing.

exception(timeout=None)[source]

Return the exception raised by the call that the future represents.

Parameters:

timeout – The number of seconds to wait for the exception if the future isn’t done. If None, then there is no limit on the wait time.

Returns:

The exception raised by the call that the future represents or None if the call completed without raising.

Raises:
  • CancelledError – If the future was cancelled.

  • TimeoutError – If the future didn’t finish executing before the given timeout.

get_headers() dict | None[source]
get_progress() int[source]
get_size() int[source]
get_stream_id() int[source]
result(timeout=None) Any[source]

Return the result of the call that the future represents.

Parameters:

timeout – The number of seconds to wait for the result if the future isn’t done. If None, then there is no limit on the wait time.

Returns:

The final result

Raises:
  • CancelledError – If the future was cancelled.

  • TimeoutError – If the future didn’t finish executing before the given timeout.

running()[source]

Return True if the future is currently executing.

set_exception(exception)[source]

Sets the result of the future as being the given exception.

set_progress(progress: int)[source]
set_result(value: Any)[source]

Sets the return value of work associated with the future.

set_size(size: int)[source]