Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why it can't use pool when calling pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=1, max_nn=30)) #7133

Closed
3 tasks done
liang00fan opened this issue Jan 10, 2025 · 2 comments
Labels
bug Not a build issue, this is likely a bug.

Comments

@liang00fan
Copy link

Checklist

Describe the issue

I try to use pcd.estimate_normals and i want to use pool to accelerate. but it will stuck.

Steps to reproduce the bug

import os
import threading
from functools import partial
from multiprocessing import Pool

import open3d as o3d
import numpy as np
import glob
import torch
# from scipy.spatial import distance
from sklearn.neighbors import NearestNeighbors
from tqdm import tqdm

normals_lock = threading.Lock()
def process(pth_path, output_dir):
    print(pth_path)

    cityname = os.path.basename(os.path.dirname(os.path.dirname(pth_path)))
    # print("cityname:", cityname)

    type_name = os.path.basename(os.path.dirname(pth_path))
    # print("Subfolder name:", type_name)

    file_name = os.path.basename(pth_path)

    output_pth_dir = os.path.join(output_dir, cityname, type_name)
    os.makedirs(output_pth_dir, exist_ok=True)
    data = torch.load(pth_path)
    try:
        xyz_origin, rgb, label = data
        pcd = o3d.geometry.PointCloud()
        pcd.points = o3d.utility.Vector3dVector(xyz_origin)
        pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=1, max_nn=30))
        ...
        torch.save(...)
    except:
        print(f'skip {pth_path}')


def process_entry(data, args):
    output_dir = args
    process(pth_path=data, output_dir=output_dir)


if __name__ == '__main__':
    
    pths=['*.pcd']  # pcd files
    # for p in pths:           # work success
    #     process(p, output_dir)

    with Pool(processes=1) as pool:
        pool.map(partial(process_entry, args=(output_dir)), pths)

Error message

no error message , it will stuck whiling using Pool.

Expected behavior

no

Open3D, Python and System information

- Operating system: Ubuntu 20.04
- Python version: Python 3.8 
- Open3D version: 0.18.0
- System architecture: x86
- Is this a remote workstation?: yes
- How did you install Open3D?: pip 
- Compiler version (if built from source): gcc 7.5

Additional information

no

@liang00fan liang00fan added the bug Not a build issue, this is likely a bug. label Jan 10, 2025
@ssheorey
Copy link
Member

Open3D uses multithreading. If you want to mix multiprocessing and multithreading in Python, you need to use forkserver or spawn methods for creating new processes, not the default 'fork'. See Python multiprocessing docs.

@liang00fan
Copy link
Author

very thanks
it works now after add multiprocessing.set_start_method("spawn")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not a build issue, this is likely a bug.
Projects
None yet
Development

No branches or pull requests

2 participants