Skip to content

set_forkserver_preload should check type of elements in passed list #107963

Description

@mawi2017

Checklist

  • I am confident this is a bug in CPython, not a bug in a third-party project
  • I have searched the CPython issue tracker,
    and am confident this bug has not been reported before

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

Python 3.10.12 (main, Jul 5 2023, 18:54:27) [GCC 11.2.0]

A clear and concise description of the bug:

The code for set_forkserver_preload (also in the latest main branch) should check the type of the elements passed through the module_names parameter, but instead checks the elements of self._preload_modules.

Code for reproducing:

#!/usr/bin/env python3
import multiprocessing as mp
import time

def work(param):
    print("work")

if __name__ == '__main__':
    ctx = mp.get_context('forkserver')
    ctx.set_forkserver_preload(['time', 1])
    
    with ctx.Pool(2) as p:
        p.map(work, [0, 1, 2, 3 ])

Raises error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File ".../lib/python3.10/multiprocessing/forkserver.py", line 178, in main
    __import__(modname)
TypeError: __import__() argument 1 must be str, not int

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13only security fixestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions