stouputils 1.15.0__tar.gz → 1.15.1__tar.gz

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.
Files changed (139) hide show
  1. {stouputils-1.15.0 → stouputils-1.15.1}/PKG-INFO +1 -1
  2. {stouputils-1.15.0 → stouputils-1.15.1}/pyproject.toml +1 -1
  3. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/parallel.py +88 -2
  4. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/parallel.pyi +21 -1
  5. {stouputils-1.15.0 → stouputils-1.15.1}/README.md +0 -0
  6. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/__init__.py +0 -0
  7. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/__init__.pyi +0 -0
  8. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/__main__.py +0 -0
  9. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/_deprecated.py +0 -0
  10. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/_deprecated.pyi +0 -0
  11. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/all_doctests.py +0 -0
  12. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/all_doctests.pyi +0 -0
  13. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/__init__.py +0 -0
  14. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/__init__.pyi +0 -0
  15. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/automatic_docs.py +0 -0
  16. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/automatic_docs.pyi +0 -0
  17. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/upscaler/__init__.py +0 -0
  18. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/upscaler/__init__.pyi +0 -0
  19. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/upscaler/config.py +0 -0
  20. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/upscaler/config.pyi +0 -0
  21. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/upscaler/image.py +0 -0
  22. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/upscaler/image.pyi +0 -0
  23. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/upscaler/video.py +0 -0
  24. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/applications/upscaler/video.pyi +0 -0
  25. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/archive.py +0 -0
  26. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/archive.pyi +0 -0
  27. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/backup.py +0 -0
  28. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/backup.pyi +0 -0
  29. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/collections.py +0 -0
  30. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/collections.pyi +0 -0
  31. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/__init__.py +0 -0
  32. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/__init__.pyi +0 -0
  33. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/cd_utils.py +0 -0
  34. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/cd_utils.pyi +0 -0
  35. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/github.py +0 -0
  36. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/github.pyi +0 -0
  37. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/pypi.py +0 -0
  38. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/pypi.pyi +0 -0
  39. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/pyproject.py +0 -0
  40. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/pyproject.pyi +0 -0
  41. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/stubs.py +0 -0
  42. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/continuous_delivery/stubs.pyi +0 -0
  43. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/ctx.py +0 -0
  44. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/ctx.pyi +0 -0
  45. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/config/get.py +0 -0
  46. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/config/set.py +0 -0
  47. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/__init__.py +0 -0
  48. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/auto_contrast.py +0 -0
  49. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/axis_flip.py +0 -0
  50. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/bias_field_correction.py +0 -0
  51. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/binary_threshold.py +0 -0
  52. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/blur.py +0 -0
  53. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/brightness.py +0 -0
  54. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/canny.py +0 -0
  55. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/clahe.py +0 -0
  56. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/common.py +0 -0
  57. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/contrast.py +0 -0
  58. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/curvature_flow_filter.py +0 -0
  59. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/denoise.py +0 -0
  60. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/histogram_equalization.py +0 -0
  61. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/invert.py +0 -0
  62. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/laplacian.py +0 -0
  63. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/median_blur.py +0 -0
  64. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/noise.py +0 -0
  65. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/normalize.py +0 -0
  66. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/random_erase.py +0 -0
  67. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/resize.py +0 -0
  68. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/rotation.py +0 -0
  69. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/salt_pepper.py +0 -0
  70. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/sharpening.py +0 -0
  71. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/shearing.py +0 -0
  72. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/threshold.py +0 -0
  73. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/translation.py +0 -0
  74. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image/zoom.py +0 -0
  75. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image_augmentation.py +0 -0
  76. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/image_preprocess.py +0 -0
  77. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/prosthesis_detection.py +0 -0
  78. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/data_processing/technique.py +0 -0
  79. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/dataset/__init__.py +0 -0
  80. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/dataset/dataset.py +0 -0
  81. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/dataset/dataset_loader.py +0 -0
  82. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/dataset/grouping_strategy.py +0 -0
  83. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/dataset/image_loader.py +0 -0
  84. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/dataset/xy_tuple.py +0 -0
  85. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/metric_dictionnary.py +0 -0
  86. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/metric_utils.py +0 -0
  87. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/mlflow_utils.py +0 -0
  88. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/abstract_model.py +0 -0
  89. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/all.py +0 -0
  90. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/base_keras.py +0 -0
  91. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/all.py +0 -0
  92. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/convnext.py +0 -0
  93. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/densenet.py +0 -0
  94. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/efficientnet.py +0 -0
  95. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/mobilenet.py +0 -0
  96. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/resnet.py +0 -0
  97. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/squeezenet.py +0 -0
  98. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/vgg.py +0 -0
  99. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras/xception.py +0 -0
  100. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/callbacks/__init__.py +0 -0
  101. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/callbacks/colored_progress_bar.py +0 -0
  102. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/callbacks/learning_rate_finder.py +0 -0
  103. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/callbacks/model_checkpoint_v2.py +0 -0
  104. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/callbacks/progressive_unfreezing.py +0 -0
  105. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/callbacks/warmup_scheduler.py +0 -0
  106. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/losses/__init__.py +0 -0
  107. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/losses/next_generation_loss.py +0 -0
  108. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/keras_utils/visualizations.py +0 -0
  109. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/model_interface.py +0 -0
  110. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/models/sandbox.py +0 -0
  111. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/range_tuple.py +0 -0
  112. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/scripts/augment_dataset.py +0 -0
  113. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/scripts/exhaustive_process.py +0 -0
  114. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/scripts/preprocess_dataset.py +0 -0
  115. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/scripts/routine.py +0 -0
  116. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/data_science/utils.py +0 -0
  117. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/decorators.py +0 -0
  118. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/decorators.pyi +0 -0
  119. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/image.py +0 -0
  120. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/image.pyi +0 -0
  121. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/__init__.py +0 -0
  122. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/__init__.pyi +0 -0
  123. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/common.py +0 -0
  124. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/common.pyi +0 -0
  125. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/downloader.py +0 -0
  126. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/downloader.pyi +0 -0
  127. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/linux.py +0 -0
  128. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/linux.pyi +0 -0
  129. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/main.py +0 -0
  130. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/main.pyi +0 -0
  131. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/windows.py +0 -0
  132. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/installer/windows.pyi +0 -0
  133. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/io.py +0 -0
  134. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/io.pyi +0 -0
  135. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/print.py +0 -0
  136. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/print.pyi +0 -0
  137. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/py.typed +0 -0
  138. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/version_pkg.py +0 -0
  139. {stouputils-1.15.0 → stouputils-1.15.1}/stouputils/version_pkg.pyi +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: stouputils
3
- Version: 1.15.0
3
+ Version: 1.15.1
4
4
  Summary: Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more.
5
5
  Keywords: utilities,tools,helpers,development,python
6
6
  Author: Stoupy51
@@ -8,7 +8,7 @@ module-root = ""
8
8
 
9
9
  [project]
10
10
  name = "stouputils"
11
- version = "1.15.0"
11
+ version = "1.15.1"
12
12
  description = "Stouputils is a collection of utility modules designed to simplify and enhance the development process. It includes a range of tools for tasks such as execution of doctests, display utilities, decorators, as well as context managers, and many more."
13
13
  readme = "README.md"
14
14
  keywords = ["utilities", "tools", "helpers", "development", "python"]
@@ -7,6 +7,16 @@ This module provides utility functions for parallel processing, such as:
7
7
 
8
8
  I highly encourage you to read the function docstrings to understand when to use each method.
9
9
 
10
+ Priority (nice) mapping for multiprocessing():
11
+
12
+ - Unix-style values from -20 (highest priority) to 19 (lowest priority)
13
+ - Windows automatic mapping:
14
+ * -20 to -10: HIGH_PRIORITY_CLASS
15
+ * -9 to -1: ABOVE_NORMAL_PRIORITY_CLASS
16
+ * 0: NORMAL_PRIORITY_CLASS
17
+ * 1 to 9: BELOW_NORMAL_PRIORITY_CLASS
18
+ * 10 to 19: IDLE_PRIORITY_CLASS
19
+
10
20
  .. image:: https://raw.githubusercontent.com/Stoupy51/stouputils/refs/heads/main/assets/parallel_module.gif
11
21
  :alt: stouputils parallel examples
12
22
  """
@@ -42,6 +52,7 @@ def multiprocessing[T, R](
42
52
  desc: str = "",
43
53
  max_workers: int | float = CPU_COUNT,
44
54
  delay_first_calls: float = 0,
55
+ nice: int | None = None,
45
56
  color: str = MAGENTA,
46
57
  bar_format: str = BAR_FORMAT,
47
58
  ascii: bool = False,
@@ -69,6 +80,11 @@ def multiprocessing[T, R](
69
80
  delay_first_calls (float): Apply i*delay_first_calls seconds delay to the first "max_workers" calls.
70
81
  For instance, the first process will be delayed by 0 seconds, the second by 1 second, etc.
71
82
  (Defaults to 0): This can be useful to avoid functions being called in the same second.
83
+ nice (int | None): Adjust the priority of worker processes (Defaults to None).
84
+ Use Unix-style values: -20 (highest priority) to 19 (lowest priority).
85
+ Positive values reduce priority, negative values increase it.
86
+ Automatically converted to appropriate priority class on Windows.
87
+ If None, no priority adjustment is made.
72
88
  color (str): Color of the progress bar (Defaults to MAGENTA)
73
89
  bar_format (str): Format of the progress bar (Defaults to BAR_FORMAT)
74
90
  ascii (bool): Whether to use ASCII or Unicode characters for the progress bar
@@ -140,13 +156,21 @@ def multiprocessing[T, R](
140
156
  # Do multiprocessing only if there is more than 1 argument and more than 1 CPU
141
157
  if max_workers > 1 and len(args) > 1:
142
158
  def process() -> list[Any]:
159
+ # Wrap function with nice if specified
160
+ if nice is not None:
161
+ wrapped_args = [(nice, func, arg) for arg in args]
162
+ wrapped_func = _nice_wrapper
163
+ else:
164
+ wrapped_args = args
165
+ wrapped_func = func
166
+
143
167
  if verbose:
144
168
  return list(process_map(
145
- func, args, max_workers=max_workers, chunksize=chunksize, desc=desc, bar_format=bar_format, ascii=ascii, **tqdm_kwargs
169
+ wrapped_func, wrapped_args, max_workers=max_workers, chunksize=chunksize, desc=desc, bar_format=bar_format, ascii=ascii, **tqdm_kwargs
146
170
  )) # type: ignore
147
171
  else:
148
172
  with Pool(max_workers) as pool:
149
- return list(pool.map(func, args, chunksize=chunksize)) # type: ignore
173
+ return list(pool.map(wrapped_func, wrapped_args, chunksize=chunksize)) # type: ignore
150
174
  try:
151
175
  return process()
152
176
  except RuntimeError as e:
@@ -382,6 +406,68 @@ def run_in_subprocess[R](
382
406
  raise RuntimeError("Subprocess did not return any result") from e
383
407
 
384
408
 
409
+ # "Private" function to wrap function execution with nice priority (must be at module level for pickling)
410
+ def _nice_wrapper[T, R](args: tuple[int, Callable[[T], R], T]) -> R:
411
+ """ Wrapper that applies nice priority then executes the function.
412
+
413
+ Args:
414
+ args (tuple): Tuple containing (nice_value, func, arg)
415
+
416
+ Returns:
417
+ R: Result of the function execution
418
+ """
419
+ nice_value, func, arg = args
420
+ _set_process_priority(nice_value)
421
+ return func(arg)
422
+
423
+ # "Private" function to set process priority (must be at module level for pickling on Windows)
424
+ def _set_process_priority(nice_value: int) -> None:
425
+ """ Set the priority of the current process.
426
+
427
+ Args:
428
+ nice_value (int): Unix-style priority value (-20 to 19)
429
+ """
430
+ try:
431
+ import sys
432
+ if sys.platform == "win32":
433
+ # Map Unix nice values to Windows priority classes
434
+ # -20 to -10: HIGH, -9 to -1: ABOVE_NORMAL, 0: NORMAL, 1-9: BELOW_NORMAL, 10-19: IDLE
435
+ try:
436
+ import psutil
437
+ if nice_value <= -10:
438
+ priority = psutil.HIGH_PRIORITY_CLASS
439
+ elif nice_value < 0:
440
+ priority = psutil.ABOVE_NORMAL_PRIORITY_CLASS
441
+ elif nice_value == 0:
442
+ priority = psutil.NORMAL_PRIORITY_CLASS
443
+ elif nice_value < 10:
444
+ priority = psutil.BELOW_NORMAL_PRIORITY_CLASS
445
+ else:
446
+ priority = psutil.IDLE_PRIORITY_CLASS
447
+ psutil.Process().nice(priority)
448
+ except ImportError:
449
+ # Fallback to ctypes if psutil is not available
450
+ import ctypes
451
+ # Windows priority class constants
452
+ if nice_value <= -10:
453
+ priority = 0x00000080 # HIGH_PRIORITY_CLASS
454
+ elif nice_value < 0:
455
+ priority = 0x00008000 # ABOVE_NORMAL_PRIORITY_CLASS
456
+ elif nice_value == 0:
457
+ priority = 0x00000020 # NORMAL_PRIORITY_CLASS
458
+ elif nice_value < 10:
459
+ priority = 0x00004000 # BELOW_NORMAL_PRIORITY_CLASS
460
+ else:
461
+ priority = 0x00000040 # IDLE_PRIORITY_CLASS
462
+ kernel32 = ctypes.windll.kernel32
463
+ handle = kernel32.GetCurrentProcess()
464
+ kernel32.SetPriorityClass(handle, priority)
465
+ else:
466
+ # Unix-like systems
467
+ os.nice(nice_value)
468
+ except Exception:
469
+ pass # Silently ignore if we can't set priority
470
+
385
471
  # "Private" function for subprocess wrapper (must be at module level for pickling on Windows)
386
472
  def _subprocess_wrapper[R](
387
473
  result_queue: Any,
@@ -10,7 +10,7 @@ CPU_COUNT: int
10
10
  T = TypeVar('T')
11
11
  R = TypeVar('R')
12
12
 
13
- def multiprocessing[T, R](func: Callable[..., R] | list[Callable[..., R]], args: Iterable[T], use_starmap: bool = False, chunksize: int = 1, desc: str = '', max_workers: int | float = ..., delay_first_calls: float = 0, color: str = ..., bar_format: str = ..., ascii: bool = False, smooth_tqdm: bool = True, **tqdm_kwargs: Any) -> list[R]:
13
+ def multiprocessing[T, R](func: Callable[..., R] | list[Callable[..., R]], args: Iterable[T], use_starmap: bool = False, chunksize: int = 1, desc: str = '', max_workers: int | float = ..., delay_first_calls: float = 0, nice: int | None = None, color: str = ..., bar_format: str = ..., ascii: bool = False, smooth_tqdm: bool = True, **tqdm_kwargs: Any) -> list[R]:
14
14
  ''' Method to execute a function in parallel using multiprocessing
15
15
 
16
16
  \t- For CPU-bound operations where the GIL (Global Interpreter Lock) is a bottleneck.
@@ -32,6 +32,11 @@ def multiprocessing[T, R](func: Callable[..., R] | list[Callable[..., R]], args:
32
32
  \t\tdelay_first_calls\t(float):\t\t\tApply i*delay_first_calls seconds delay to the first "max_workers" calls.
33
33
  \t\t\tFor instance, the first process will be delayed by 0 seconds, the second by 1 second, etc.
34
34
  \t\t\t(Defaults to 0): This can be useful to avoid functions being called in the same second.
35
+ \t\tnice\t\t\t\t(int | None):\t\tAdjust the priority of worker processes (Defaults to None).
36
+ \t\t\tUse Unix-style values: -20 (highest priority) to 19 (lowest priority).
37
+ \t\t\tPositive values reduce priority, negative values increase it.
38
+ \t\t\tAutomatically converted to appropriate priority class on Windows.
39
+ \t\t\tIf None, no priority adjustment is made.
35
40
  \t\tcolor\t\t\t\t(str):\t\t\t\tColor of the progress bar (Defaults to MAGENTA)
36
41
  \t\tbar_format\t\t\t(str):\t\t\t\tFormat of the progress bar (Defaults to BAR_FORMAT)
37
42
  \t\tascii\t\t\t\t(bool):\t\t\t\tWhether to use ASCII or Unicode characters for the progress bar
@@ -169,6 +174,21 @@ def run_in_subprocess[R](func: Callable[..., R], *args: Any, timeout: float | No
169
174
  \t\t\t> # With timeout to prevent hanging
170
175
  \t\t\t> run_in_subprocess(some_gpu_func, data, timeout=300.0)
171
176
  \t'''
177
+ def _nice_wrapper[T, R](args: tuple[int, Callable[[T], R], T]) -> R:
178
+ """ Wrapper that applies nice priority then executes the function.
179
+
180
+ \tArgs:
181
+ \t\targs (tuple): Tuple containing (nice_value, func, arg)
182
+
183
+ \tReturns:
184
+ \t\tR: Result of the function execution
185
+ \t"""
186
+ def _set_process_priority(nice_value: int) -> None:
187
+ """ Set the priority of the current process.
188
+
189
+ \tArgs:
190
+ \t\tnice_value (int): Unix-style priority value (-20 to 19)
191
+ \t"""
172
192
  def _subprocess_wrapper[R](result_queue: Any, func: Callable[..., R], args: tuple[Any, ...], kwargs: dict[str, Any]) -> None:
173
193
  """ Wrapper function to execute the target function and store the result in the queue.
174
194
 
File without changes