libtcspc.PyBucketSource¶
- class libtcspc.PyBucketSource[source]¶
Bases:
ABCBucket source implemented in Python and supplied as an argument upon creation of the execution context.
A
PyBucketSourceprovides the storage that backs the buckets emitted by processors such asAcquire,Batch,BatchFromBytes, andReadBinaryStream. It is bound to a graph by passing aParamas thebuffer_providerargument of such a processor, and the concrete instance is supplied to theExecutionContextat execution time.When a bucket whose storage came from a
PyBucketSourceflows unmodified to aPySink, the sink receives a NumPy array that is a zero-copy view of the buffer originally returned bybucket_of_size, trimmed to the bucket’s valid length. The buffer is kept alive for as long as the bucket (or the sink’s view of it) exists.A
PyBucketSourcesupports shared views and may be used with processors that require a sharable bucket source. A read-only shared view delivered to aPySinkis likewise zero-copy: a read-only NumPy array co-owning the same buffer.See also
BucketSourceBuilt-in C++-side bucket sources.
- abstractmethod bucket_of_size(size)[source]¶
Return a buffer to back a bucket of at least
sizeelements.- Parameters:
size (int) – The minimum number of elements the returned buffer must hold.
- Returns:
A buffer-protocol object (typically a NumPy array) of length at least
sizewhose dtype matches the element type of the buckets requested by the processor. The bucket will use the firstsizeelements as its storage.- Return type:
Any
Notes
An implementation must not retain or reuse a buffer it has already returned while the corresponding bucket, or any shared view derived from it, may still be in flight; doing so corrupts data still being processed.