Enables multiprocessing with caching, eliminating the need for main, and ensuring unique results without duplicates
pip install multiprocca
Tested against Python 3.11 / Windows 10
import sys
from a_cv_imwrite_imread_plus import open_image_in_cv
from locate_pixelcolor_c import search_colors
import subprocess
import numpy as np
import cv2
from list_all_files_recursively import get_folder_file_complete_path
from multiprocca import start_multiprocessing
from multiprocca.proclauncher import MultiProcExecution
def function_subxxx(x):
exec("import cv2", globals())
exec("import numpy as np", globals())
pic = cv2.imread(x)
b, g, r = pic[..., 0], pic[..., 1], pic[..., 2]
return np.where(((b == 255) & (g == 255) & (r == 255)))
def function_sub1(file):
exec("import subprocess", globals())
exec("import numpy as np", globals())
with open(file, mode="rb") as f:
da = f.read()
p = subprocess.run(
[
r"""C:\Program Files\Tesseract-OCR\tesseract.exe""",
"-c",
"tessedit_create_tsv=1",
"-l",
"por",
"-",
"stdout",
],
input=da,
capture_output=True,
)
return p.stderr, p.stdout
def function_sub(pic, colors):
try:
exec("""import sys""", globals())
exec("""import numpy as np""", globals())
exec("""import cv2""", globals())
exec("""from locate_pixelcolor_c import search_colors""", globals())
exec("""from a_cv_imwrite_imread_plus import open_image_in_cv""", globals())
colorsrev = np.array([list(q) for q in (map(reversed, colors))], dtype=np.uint8)
pic = open_image_in_cv(pic, channels_in_output=3)
sc = search_colors(pic=pic, colors=colorsrev)
if len(sc) == 1:
if np.sum(sc) == 0:
if not (pic[0, 0]) in colorsrev:
sc = np.array([[-1, -1]], dtype=np.int32)
return sc
except Exception as e:
sys.stderr.write(f"{e}\n")
sys.stderr.flush()
return np.array([[-1, -1]], dtype=np.int32)
colors1 = (
(69, 71, 66),
(255, 255, 255),
(153, 155, 144),
(55, 57, 52),
(136, 138, 127),
(56, 58, 53),
(54, 56, 51),
(0, 180, 252),
)
allpi = [
x.path
for x in get_folder_file_complete_path(r"C:\testfolderall")
if x.ext == ".png"
]
f = [
MultiProcExecution(fu=function_sub, args=(o, colors1), kwargstuple=())
for o in allpi
]
formated_data, raw_data = start_multiprocessing(
it=f,
usecache=True,
processes=5,
chunks=1,
print_stdout=False,
print_stderr=False,
)
def start_multiprocessing(
it,
usecache=True,
processes=5,
chunks=1,
print_stdout=False,
print_stderr=True,
):
r"""
Initiates parallel processing on the given iterable using multiprocessing.
Args:
it (iterable): The iterable containing data to be processed in parallel.
usecache (bool, optional): Flag indicating whether to enable caching of results.
Defaults to True.
processes (int, optional): The number of parallel processes to be spawned.
Defaults to 5.
chunks (int, optional): The number of items to be processed in each task chunk.
Defaults to 1.
print_stdout (bool, optional): Flag indicating whether to print stdout of subprocesses.
Defaults to False.
print_stderr (bool, optional): Flag indicating whether to print stderr of subprocesses.
Defaults to True.
Returns:
tuple: A tuple containing two elements:
1. A dictionary mapping input indices to corresponding processed results.
2. A list containing essential data, including hash_and_result, hash_int_map_small,
original_object, and mapping_dict.
Metadata
Release files for multiprocca 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| multiprocca-0.10.tar.gz | 7.1 kB | Without provenance | Details for multiprocca-0.10.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| multiprocca-0.10-py3-none-any.whl | Python 3 | none | any | Details for multiprocca-0.10-py3-none-any.whl |
Total release size: 16.2 kB
Release files / multiprocca-0.10.tar.gz
| Download URL | multiprocca-0.10.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3baed48091e785f0d1700bc5998d3098795f76d7a8d0deab1069040b0a0a04a3
|
|
BLAKE2b-256 checksum How to use checksums |
06f64b63a45133823b05a8b185261476bd0641eb6ddcc2a1f2bc0987594f26b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / multiprocca-0.10-py3-none-any.whl
| Download URL | multiprocca-0.10-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6e2949b2f764f9bcf3bdc1bb6d63abaa2ba4f51cd93c394d50df03c89f035264
|
|
BLAKE2b-256 checksum How to use checksums |
15570a1c137c2792d43dd7e579839ba2ea0be5da990d545964f895f169092bdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for multiprocca 0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.