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

multiprocessing freeze_support needed outside win32 #76327

Open
dancol mannequin opened this issue Nov 27, 2017 · 12 comments
Open

multiprocessing freeze_support needed outside win32 #76327

dancol mannequin opened this issue Nov 27, 2017 · 12 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir topic-multiprocessing type-bug An unexpected behavior, bug, or error

Comments

@dancol
Copy link
Mannequin

dancol mannequin commented Nov 27, 2017

BPO 32146
Nosy @pfmoore, @ronaldoussoren, @pitrou, @tjguk, @zware, @zooba, @applio, @bbayles, @miss-islington, @orn688
PRs
  • bpo-32146: multiprocessing freeze_support needed outside win32 #5195
  • bpo-32146: Add documentation about frozen executables on Unix #5850
  • [3.7] bpo-32146: Add documentation about frozen executables on Unix (GH-5850) #11511
  • [3.7] bpo-32146: Add documentation about frozen executables on Unix (GH-5850) #11511
  • [3.7] bpo-32146: Add documentation about frozen executables on Unix (GH-5850) #11511
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2017-11-27.10:33:55.596>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'multiprocessing freeze_support needed outside win32'
    updated_at = <Date 2021-03-29.12:34:42.683>
    user = 'https://bugs.python.org/dancol'

    bugs.python.org fields:

    activity = <Date 2021-03-29.12:34:42.683>
    actor = 'vstinner'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2017-11-27.10:33:55.596>
    creator = 'dancol'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32146
    keywords = ['patch']
    message_count = 11.0
    messages = ['307043', '307527', '309886', '311274', '333411', '333412', '333414', '333432', '333460', '333533', '334201']
    nosy_count = 11.0
    nosy_names = ['paul.moore', 'ronaldoussoren', 'pitrou', 'tim.golden', 'zach.ware', 'steve.dower', 'dancol', 'davin', 'bbayles', 'miss-islington', 'onew']
    pr_nums = ['5195', '5850', '11511', '11511', '11511']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue32146'
    versions = ['Python 3.7', 'Python 3.8']

    Linked PRs

    @dancol
    Copy link
    Mannequin Author

    dancol mannequin commented Nov 27, 2017

    multiprocessing's freeze_support makes freshly-launched subprocesses integrate correctly until the multiprocessing ecosystem even when the main executable is some application binary instead of a Python interpreter. The documentation and code assume that this support is needed only on win32, but it's equally applicable to POSIX systems using the spawn strategy in combination with systems like cx_freeze.

    In particular:

    1. The special case in context.py's version of freeze_support() for win32 should be removed

    2. The semaphore tracker should correctly tickle the freeze support

    3. The documentation should be updated to be platform-neutral

    @dancol dancol mannequin added 3.8 only security fixes 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Nov 27, 2017
    @pitrou
    Copy link
    Member

    pitrou commented Dec 3, 2017

    Thank you for reporting this. Would you like to submit a PR?

    @pitrou pitrou removed the 3.8 only security fixes label Dec 3, 2017
    @bbayles
    Copy link
    Mannequin

    bbayles mannequin commented Jan 13, 2018

    I ran into this issue, and found references to it on StackOverflow [1] and GitHub [2] as well. I found that the problem applies to both the 'spawn' and 'forkserver' start methods on Linux.

    I made an attempt to implement dancol's fix above. (1) and (3) are straightforward, but if there's an elegant way to do the "tickle" in (2) I wasn't able to figure it out?

    My branch [3] has something that seems to work with the 'spawn' method and cx_Freeze. Perhaps someone could look at that and tell me if I'm on a reasonable track? If so, I can attempt to extend the method to cover 'forkserver' as well.

    [1] https://stackoverflow.com/q/47325297/353839

    [2] marcelotduarte/cx_Freeze#264

    [3] master...bbayles:bpo-32146-freeze_support

    @bbayles
    Copy link
    Mannequin

    bbayles mannequin commented Jan 30, 2018

    I presume it's too late to get my pull request in for 3.7, but perhaps we could get a note in the documentation for this before release?

    That could be as simple as:

    .. warning::
    
    The ``'spawn'`` and ``'forkserver'`` start methods cannot currently be used with "frozen" executables (i.e., binaries produced by packages like **PyInstaller** and **cx_Freeze**) on Unix. The ``'fork'`` start method does work.
    

    I will make that into a PR if it seems like a good option.

    @pitrou
    Copy link
    Member

    pitrou commented Jan 10, 2019

    I'm sorry about not seeing your PR before. Would you like to update it against current git master?

    (note I'm not thrilled by the use of the "ast" module; I hope we can change the command-line args so that this isn't needed)

    @vstinner
    Copy link
    Member

    New changeset bab4bbb by Victor Stinner (Bo Bayles) in branch 'master':
    bpo-32146: Add documentation about frozen executables on Unix (GH-5850)
    bab4bbb

    @miss-islington
    Copy link
    Contributor

    New changeset b9cd38f by Miss Islington (bot) in branch '3.7':
    bpo-32146: Add documentation about frozen executables on Unix (GH-5850)
    b9cd38f

    @bbayles
    Copy link
    Mannequin

    bbayles mannequin commented Jan 11, 2019

    Thanks for the note. I've merged in master and fixed a conflict in the test file.

    In an earlier rev I tried to do the argument parsing without ast.literal_eval, but found it awkward to support all the ways [1] can manifest. You might have a better idea?

    [1] https://github.com/python/cpython/blob/3.7/Lib/multiprocessing/forkserver.py#L106-L107

    @pitrou
    Copy link
    Member

    pitrou commented Jan 11, 2019

    The key here would be to replace function execution with module execution and command-line arguments.

    So instead of:

    python -c 'from multiprocessing.forkserver import main; main(ARG1, ARG2...)'

    you would do:

    python -m multiprocessing.forkserver ARG1 ARG2 ....

    Then it should become easy to extract the concatenated command lines.

    (and if that works, please do the same for semaphore_tracker ;-))

    @pitrou pitrou added the 3.8 only security fixes label Jan 11, 2019
    @bbayles
    Copy link
    Mannequin

    bbayles mannequin commented Jan 12, 2019

    I'm currently having difficulty getting either cx_Freeze or PyInstaller to work with Python 3.8, which is hindering testing. I also no longer have easy access to a Windows environment.

    If I change the implementation to use -m instead of -c would you be able to test?

    @pitrou
    Copy link
    Member

    pitrou commented Jan 22, 2019

    @bbayles Hopefully a Windows user could test if you give a step-by-step guide of what to check for.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @jonashaag
    Copy link
    Contributor

    jonashaag commented Sep 20, 2022

    The documentation still says

    Calling freeze_support() has no effect when invoked on any operating system other than Windows.

    I'm happy to submit a fix but I'm unsure what to say/write because I'm not familiar with the matter.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes 3.12 bugs and security fixes stdlib Python modules in the Lib dir topic-multiprocessing type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Development

    No branches or pull requests

    5 participants