AttributeError: 'NoneType' object has no attribute 'id' when using ray.util.multiprocessing pool

How severe does this issue affect your experience of using Ray?

  • High: It blocks me to complete my task.

Consider the following code:

from ray.util.multiprocessing import Pool

dsa_id = 1
collection_id = 1

def add_annotations(file_id):
    os.environ['RAY_ENABLE_RECORD_ACTOR_TASK_LOGGING'] = '1'
    annotations = []
    db = Database(initiate=False, drop_all=False, echo=True, host='192.168.24.1')
    file = db.get_model_by_id("wsifile", file_id)
    dsa_requests = DSARequests(url, username='user@domain.com')
    add_all_annotations_for_dsa_file_item(dsa_requests, file.remote_item_id, annotations)
    save_regions_and_annotations_to_db(db, dsa_requests, dsa_id, collection_id, file, annotations, use_file=True)
    filename = str(file.name)
    print("Finished saving annotations for file {}".format(filename))
    return filename

with Pool() as pool:
    filenames = pool.map(add_annotations, db_files_ids)
    print("Succeeded in completing files {}".format(json.dumps(filenames, indent=2)))

Despite completing the function add_annotations in an actor pool without errors. The entrypoint script will fail after running the pool with the error:

Traceback (most recent call last):
File "/tmp/ray/session_2024-11-11_23-02-59_297376_355/runtime_resources/working_dir_files/_ray_pkg_ecebe823dc2ac095/setup/yolo_nft_setup.py", line 82, in <module>
filenames = pool.map(add_annotations, db_files_ids)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ray/miniconda3/envs/raygun/lib/python3.12/site-packages/ray/util/multiprocessing/pool.py", line 844, in map
).get()
^^^^^
File "/home/ray/miniconda3/envs/raygun/lib/python3.12/site-packages/ray/util/multiprocessing/pool.py", line 351, in get
raise result.underlying
AttributeError: 'NoneType' object has no attribute 'id'

I expect like in the standard multiprocessing pool to return a list of filenames. If omit the return:

def add_annotations(file_id):
    os.environ['RAY_ENABLE_RECORD_ACTOR_TASK_LOGGING'] = '1'
    annotations = []
    db = Database(initiate=False, drop_all=False, echo=True, host='192.168.24.1')
    file = db.get_model_by_id("wsifile", file_id)
    dsa_requests = DSARequests(url, username='arosad2@emory.edu')
    add_all_annotations_for_dsa_file_item(dsa_requests, file.remote_item_id, annotations)
    save_regions_and_annotations_to_db(db, dsa_requests, dsa_id, collection_id, file, annotations, use_file=True)
    filename = str(file.name)
    print("Finished saving annotations for file {}".format(filename))

with Pool() as pool:
    pool.map(add_annotations, db_files_ids)
    # print("Succeeded in completing files {}".format(json.dumps(filenames, indent=2)))

I get the same error:

Traceback (most recent call last):
File "/tmp/ray/session_2024-11-11_23-02-59_297376_355/runtime_resources/working_dir_files/_ray_pkg_eb2c1a9598f4acd9/setup/yolo_nft_setup.py", line 81, in <module>
pool.map(add_annotations, db_files_ids)
File "/home/ray/miniconda3/envs/raygun/lib/python3.12/site-packages/ray/util/multiprocessing/pool.py", line 844, in map
).get()
^^^^^
File "/home/ray/miniconda3/envs/raygun/lib/python3.12/site-packages/ray/util/multiprocessing/pool.py", line 351, in get
raise result.underlying
AttributeError: 'NoneType' object has no attribute 'id'

Versions:
OS: Ubuntu 24.04.1 LTS
Python: Python 3.12.7
Ray: 2.38.0
Conda: 24.9.2
Docker: Docker version 27.3.1, build ce12230