Shared generator between process
Project description
Python library : cm_shared_generator
Resume
In python, it exist a generator type which can be really useful.
The cm_shared_generator
library provide a Shared_Generator which share generator between thread and process safely.
Install
Pre-required
Global requirements
- Python 3 (
sudo apt update && sudo apt install python3 -y
)
Install requirements
- Setuptools (
sudo apt update && sudo apt install python3-pip -y && pip3 install setuptools
)
Installation
python3 setup.py install
Utilization
The utilization of the Shared_Generator is quite simple. Its prototype is like :
Shared_Generator(self, arg_generator, DEFAULT_GENERATOR_TRAITMENT_FUNCTION=None, MAX_OBJECT_IN_QUEUE=len(os.sched_getaffinity(0)), TIMEOUT=None)
Its parameters are defined as :
- Required :
arg_generator
-> The generator to shared
- Optional :
DEFAULT_GENERATOR_TRAITMENT_FUNCTION
(Default : None) -> Function to treat default type of value from the generator. Possible value :Shared_Generator.DEFAULT_GENERATOR_TRAITMENT_CLASS
(Create a deep copy of the class before the insertion into the Queue).- Your own function !
MAX_OBJECT_IN_QUEUE
(Default : Nb of logical processors) : Defined the maximum of elements in the queue at the same time. ( > 0 )TIMEOUT
(Default :Shared_Generator.DEFAULT_TIMEOUT
) : Defined the timeout of Semaphores.
Example :
from cm_shared_generator import Shared_Generator
# Simple integer generator
def int_generator():
i = 0
while i<10:
i+=1
yield i
return
my_shared_generator = Shared_Generator(int_generator, MAX_OBJECT_IN_QUEUE=2) # Creation of the generator with a Maximum lenght queue of 2
my_shared_generator.start(NEW_PROCESS=True) # Launch the generator in a new process
val = my_shared_generator.next() # Get the next value of the generator
my_shared_generator.stop() # Stop the generator
For more examples, check unit tests in tests directory.
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
Close
Hashes for cm_shared_generator-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 692b9635676941f50819cd50ec4211e1c7bd6d0c7e88ec7241125e731982aeae |
|
MD5 | 451b4a1a72a5ab5c551510572f3f9876 |
|
BLAKE2b-256 | d8c527f1697c3db10e00793faf2660c52f32bc1f64ab2b99060b02eeced18868 |
Close
Hashes for cm_shared_generator-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 487421dd6c752c56e4700aac76ff5d91329c49a02b725271c676bc25c99d1c03 |
|
MD5 | a73ed2942bcb5f6608787277244b8806 |
|
BLAKE2b-256 | bac191ea61c3e09968f4c5c0c0d22694a9fe3daf1ca1b5652b5fc4a22f404c19 |