Skip to content

pathos.multiprocessing ProcessingPool crashes in input integer np.int32 object into pool(the_integer), sometimes (tbd) #301

@jcb31416

Description

@jcb31416

if replacing int(ncpu) into ncpu sometimes the process gets hanged, but it's avoided by wrapping the np.int32 object into int(). to be noted that type(ncpu) = np.int32

i don't fully understand why sometimes the problem is solved by wrapping np.int32 into int(), and others don't. should be something else, it's strange.. sth to be solved.

some context: Spyder 5.4.5 | Python 3.11.5 64-bit | Qt 5.15.2 | PyQt5 5.15.6 | Windows 10 (AMD64)

min repr example of crash: this example aims to group the parallelization in groups of 5.

import numpy as np
from pathos.multiprocessing import ProcessingPool as Pool

def f_phi(item):
    print(item)
# enddef f_phi

# Initialize a list to be grouped in blocks of 5 items
lis_1 = np.arange(0, 13)

# Total number of elements in lis_1
nn = len(lis_1)

# Create a vector to separate indices of lis_1 into groups of 5
vec = np.arange(0, nn, 5)

# Create lists for "from" (start) indices and "to" (end) indices
lis_frm = list(vec[:-1])  # "From" indices
lis_to = list(vec[1:])    # "To" indices

# Handle the remainder if the last group has fewer than 5 elements
if lis_to[-1] < (nn - 1):  # Handle the remainder group (e.g., 10 to 13)
    lis_frm += [lis_to[-1]]
    lis_to += [nn - 1]
#endif

# Number of groups to be processed
ngru = len(lis_frm)

# Initialize lists for the number of CPUs and results
lis_ncpu = [None] * ngru
lis_resp = [None] * ngru

# Loop through all groups and process them in parallel
for igro in range(len(lis_frm)):
    frm = lis_frm[igro]  # "From" index for the current group
    to = lis_to[igro]    # "To" index for the current group
    ncpu = int(lis_to[igro] - lis_frm[igro])  # Number of parallel threads (ensure it's an integer)

    # Slice the input list for the current group
    lis_argin = lis_1[frm:to]
    lis = []

    # Process the current group in parallel
    with Pool(ncpu) as pool:
        lis = pool.map(f_phi, lis_argin)
    # endwith

    # Store the results
    lis_resp[igro] = lis
# endfor

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions