xloft 0.1.23__py3-none-any.whl → 0.1.24__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of xloft might be problematic. Click here for more details.
xloft/quantum.py
CHANGED
|
@@ -45,6 +45,9 @@ class QuantumLoop:
|
|
|
45
45
|
Args:
|
|
46
46
|
quantum: Function with a task algorithm.
|
|
47
47
|
data: The data that needs to be processed.
|
|
48
|
+
max_workers: The maximum number of processes that can be used to
|
|
49
|
+
execute the given calls. If None or not given then as many
|
|
50
|
+
worker processes will be created as the machine has processors.
|
|
48
51
|
timeout: The maximum number of seconds to wait. If None, then there
|
|
49
52
|
is no limit on the wait time.
|
|
50
53
|
chunksize: The size of the chunks the iterable will be broken into
|
|
@@ -54,7 +57,7 @@ class QuantumLoop:
|
|
|
54
57
|
|
|
55
58
|
Examples:
|
|
56
59
|
>>> from xloft.quantum import LoopMode, QuantumLoop, count_qubits
|
|
57
|
-
>>> def quantum(
|
|
60
|
+
>>> def quantum(item):
|
|
58
61
|
... return item * item
|
|
59
62
|
>>> data = range(10)
|
|
60
63
|
>>> qloop = QuantumLoop(quantum, data, mode=LoopMode.PROCESS_POOL)
|
|
@@ -66,19 +69,21 @@ class QuantumLoop:
|
|
|
66
69
|
self,
|
|
67
70
|
quantum: Callable,
|
|
68
71
|
data: Iterable[Any],
|
|
72
|
+
max_workers: int | None = None,
|
|
69
73
|
timeout: float | None = None,
|
|
70
74
|
chunksize: int = 1,
|
|
71
75
|
mode: LoopMode = LoopMode.PROCESS_POOL,
|
|
72
76
|
) -> None:
|
|
73
77
|
self.quantum = quantum
|
|
74
78
|
self.data = data
|
|
79
|
+
self.max_workers = max_workers
|
|
75
80
|
self.timeout = timeout
|
|
76
81
|
self.chunksize = chunksize
|
|
77
82
|
self.mode = mode
|
|
78
83
|
|
|
79
84
|
def process_pool(self) -> list[Any]:
|
|
80
85
|
"""Better suitable for operations for which large processor resources are required."""
|
|
81
|
-
with concurrent.futures.ProcessPoolExecutor() as executor:
|
|
86
|
+
with concurrent.futures.ProcessPoolExecutor(self.max_workers) as executor:
|
|
82
87
|
results = list(
|
|
83
88
|
executor.map(
|
|
84
89
|
self.quantum,
|
|
@@ -93,7 +98,7 @@ class QuantumLoop:
|
|
|
93
98
|
"""More suitable for tasks related to input-output
|
|
94
99
|
(for example, network queries, file operations),
|
|
95
100
|
where GIL is freed during input-output operations.""" # noqa: D205, D209
|
|
96
|
-
with concurrent.futures.ThreadPoolExecutor() as executor:
|
|
101
|
+
with concurrent.futures.ThreadPoolExecutor(self.max_workers) as executor:
|
|
97
102
|
results = list(
|
|
98
103
|
executor.map(
|
|
99
104
|
self.quantum,
|
|
@@ -3,8 +3,8 @@ xloft/errors.py,sha256=GYXvi2l01VUDQSs6skiOfQsKLF6tFuUhJMqNkL7BJNI,857
|
|
|
3
3
|
xloft/humanism.py,sha256=I6q56MhviapBSWF4B_1xd77TDwQMM1jrkbl1N-fOURc,1068
|
|
4
4
|
xloft/namedtuple.py,sha256=OkAHqMaV4hN6Qj_oaOYQ9-y9x4Muv4mNrBn48T6RpiI,6818
|
|
5
5
|
xloft/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
xloft/quantum.py,sha256=
|
|
7
|
-
xloft-0.1.
|
|
8
|
-
xloft-0.1.
|
|
9
|
-
xloft-0.1.
|
|
10
|
-
xloft-0.1.
|
|
6
|
+
xloft/quantum.py,sha256=o6RUrnqBjlpxzGfRhAs_GSZwwAaqHGA591M6YEledg8,4211
|
|
7
|
+
xloft-0.1.24.dist-info/METADATA,sha256=N79k05UElgcRzAWrwW1QN9Vgdg1ZU7OlLPFqkmS2UJI,7116
|
|
8
|
+
xloft-0.1.24.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
xloft-0.1.24.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
10
|
+
xloft-0.1.24.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|