xloft 0.1.23__py3-none-any.whl → 0.1.25__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
|
|
@@ -53,11 +56,11 @@ class QuantumLoop:
|
|
|
53
56
|
mode: The operating mode for a quantum loop: LoopMode.PROCESS_POOL | LoopMode.THREAD_POOL.
|
|
54
57
|
|
|
55
58
|
Examples:
|
|
56
|
-
>>> from xloft.quantum import
|
|
57
|
-
>>> def quantum(
|
|
59
|
+
>>> from xloft.quantum import QuantumLoop
|
|
60
|
+
>>> def quantum(item):
|
|
58
61
|
... return item * item
|
|
59
62
|
>>> data = range(10)
|
|
60
|
-
>>> qloop = QuantumLoop(quantum, data
|
|
63
|
+
>>> qloop = QuantumLoop(quantum, data)
|
|
61
64
|
>>> qloop.run()
|
|
62
65
|
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|
|
63
66
|
"""
|
|
@@ -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,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xloft
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.25
|
|
4
4
|
Summary: (XLOFT) X-Library of tools
|
|
5
5
|
Project-URL: Homepage, https://github.com/kebasyaty/xloft
|
|
6
6
|
Project-URL: Repository, https://github.com/kebasyaty/xloft
|
|
@@ -183,7 +183,7 @@ def quantum(item):
|
|
|
183
183
|
|
|
184
184
|
data = range(10)
|
|
185
185
|
|
|
186
|
-
qloop = QuantumLoop(quantum, data
|
|
186
|
+
qloop = QuantumLoop(quantum, data)
|
|
187
187
|
results = qloop.run()
|
|
188
188
|
print(results) # => [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
|
|
189
189
|
```
|
|
@@ -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=0c6-vz6SilbKxtz6vJvL-9MpsByGVb4mWZvo67fwFBU,4159
|
|
7
|
+
xloft-0.1.25.dist-info/METADATA,sha256=nP-9CLu5N_XLg1p8mQYxxmZC0Va7II49LgP2gOieVYE,7088
|
|
8
|
+
xloft-0.1.25.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
9
|
+
xloft-0.1.25.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
10
|
+
xloft-0.1.25.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|