No project description provided
Project description
StreamingPool 🌊
StreamingPool is a Python library that allow user to implement custom pipelines to treat datas asynchronously.
You can add and treat datas at the same time based on Python's concurrent.futures.ThreadPoolExecutor class.
Available pools 🐋
FIFOPool: A First In First Out pool.LIFOPool: A Last In First Out pool.BasePool: A base class to let you implement your own logic of pooling from scratch.
How to use 💯
Create your pool 🐟
First you'll need to implement your own pool to describe the logic that you want :
from streamingpool import FIFOPool
class SamplePool(FIFOPool[int]):
"""
This is a sample pool that print int values
"""
def __init__(self):
super().__init__()
def process_segment(self, segment: int) -> None:
print(segment)
NB : You can specify any type of data that you need, here for the exemple I have choosed
int
And the you can start your pool !
Pool usage 🐳
To use a pool you have two choices :
Disposable usage ✔️
with SamplePool() as pool:
for i in range(10):
pool.enqueue_segment(i)
pool.pause() # Pause the pool
# ...
pool.start() # In this case resume the pool
Inline usage ✔️
pool = SamplePool()
pool.start()
for i in range(10):
pool.enqueue_segment(i)
pool.pause() # Pause the pool
# ...
pool.start() # In this case resume the pool
pool.stop() # Stop the pool when all it's data have been treated (block the thread)
Creating your own pool 🐬
As it have been said before, you can also implement your own pooling logic.
from streamingpool import BasePool, TSegment
class ListPool(BasePool[TSegment]):
__buffer: list
def __init__(self):
super().__init__()
def __init__(self):
super().__init__()
self.__buffer = list()
def enqueue_segment(self, datas: TSegment) -> None:
self.__buffer.append(datas)
def retrieve_segment(self) -> TSegment:
return self.__buffer.pop()
def is_empty(self) -> bool:
return len(self.__buffer) == 0
def clear_buffer(self) -> None:
self.__buffer = list()
def process_segment(self, segment: int) -> None:
print(segment)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file streamingpool-1.1.tar.gz.
File metadata
- Download URL: streamingpool-1.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
992608e098f30de9c7b6690e48abc17e4655255147602d5c54fe31c39d4c1317
|
|
| MD5 |
06e9d3d4d6b6afa0aa69b51074c0a42b
|
|
| BLAKE2b-256 |
64e744ba674e928fa8b6f77f9878251c99c3c80d4b533436cd64a499432d8a37
|
File details
Details for the file streamingpool-1.1-py3-none-any.whl.
File metadata
- Download URL: streamingpool-1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf3f25ef45dc75c96bfd783c3f62ac9e5f0c2317f2a20123e4a1a3ecadb920a5
|
|
| MD5 |
1fde92d3e4ec94f127132f42c14a857a
|
|
| BLAKE2b-256 |
e10e9310a448628f937e8dc9b7b6c85e5cf57d979a466637818157923ee62622
|