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

multithreading.Pool.map() crashes Windows computer #50397

Closed
acjames mannequin opened this issue May 30, 2009 · 5 comments
Closed

multithreading.Pool.map() crashes Windows computer #50397

acjames mannequin opened this issue May 30, 2009 · 5 comments
Labels
OS-windows type-feature A feature request or enhancement

Comments

@acjames
Copy link
Mannequin

acjames mannequin commented May 30, 2009

BPO 6147
Files
  • test_a10.py: test case
  • 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 = <Date 2009-06-01.03:09:25.036>
    created_at = <Date 2009-05-30.00:04:46.187>
    labels = ['type-feature', 'OS-windows']
    title = 'multithreading.Pool.map() crashes Windows computer'
    updated_at = <Date 2012-03-10.18:26:45.445>
    user = 'https://bugs.python.org/acjames'

    bugs.python.org fields:

    activity = <Date 2012-03-10.18:26:45.445>
    actor = 'valhallasw'
    assignee = 'jnoller'
    closed = True
    closed_date = <Date 2009-06-01.03:09:25.036>
    closer = 'benjamin.peterson'
    components = ['Windows']
    creation = <Date 2009-05-30.00:04:46.187>
    creator = 'ac.james'
    dependencies = []
    files = ['14119']
    hgrepos = []
    issue_num = 6147
    keywords = []
    message_count = 5.0
    messages = ['88557', '88560', '88632', '88633', '155338']
    nosy_count = 3.0
    nosy_names = ['jnoller', 'ac.james', 'valhallasw']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = None
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue6147'
    versions = ['Python 2.6']

    @acjames
    Copy link
    Mannequin Author

    acjames mannequin commented May 30, 2009

    When calling multithreading.Pool().map() to distribute computational
    load I've recently got system crashes.

    The attached minimalist script exhibits this issue.
    On a Windows Vista home premium sp1 running Python 2.6.2 on a dual-core
    laptop, the script stops executing at
    threading.Condition(threading.Lock()).wait() called from
    multithreading.ApplyResult().wait() called from
    multithreading.ApplyResult().get() called from
    multithreading.Pool().map() and then compiles the original script as it
    starts the script form the beggining twice simultaneously. The printed
    output gets mixed content and both new instances of the script hit the
    same problem and spawn more instances. All old processes are still
    active in memory so this leads to system resources being fully consumed.

    This behavior started occurring recently, immediately after attempting
    to install a Python .Egg package. I have uninstalled python an all
    extensions, restarted windows, deleted all orphan files and registry
    keys I could find, restarted windows, and then re-installed a fresh
    download of 2.6.2, but the problem remains.

    The error output retrievable from Keyboard Interrupt (which only works
    when script was started on commandline) contains several copies of """
    Traceback:
    file "<string>", line 1, in <module>
    'import site' failed: use -v for traceback
    script opening print statement
    script opening print statement
    'import site' failed: use -v for traceback
    File "C:\Python26\lib\multiprocessing\forking.py", line 341, in main
    prepare(preparation_data)
    File "C:\Python26\lib\multiprocessing\forking.py", line 456, in prepare
    '__parents_main__', file, path_name, etc
    File "H:\builder26\test_a6.py", line 1, in <module>
    Traceback:
    from custom_module import *
    """
    amoung many pieces thereof stuffed bytewise into other pieces thereof.

    Identical code running in Unix operates just fine, and the identical
    code worked on my machine last week. Reproducability of this error is
    thus doubtful. Repeatability is perfect however.

    Any possible workarounds and/or understanding of root cause is
    appreciated for this very rare extreme error.

    @acjames acjames mannequin added type-crash A hard crash of the interpreter, possibly with a core dump OS-windows labels May 30, 2009
    @jnoller
    Copy link
    Mannequin

    jnoller mannequin commented May 30, 2009

    Can you wrap the execution of the main code in a if __name__ ==
    "__main__": block, as shown in the documentation? Failure to do so can
    cause a fork bomb on windows

    @acjames
    Copy link
    Mannequin Author

    acjames mannequin commented Jun 1, 2009

    Ok Jesse, that did stop the bomb problem.
    Unfortunately the real code belongs in a scientific research
    distributable module that is called by another function in the module
    where both have been imported into the script that is run. So it isn't
    being called by __main__ in the first place. So we'll have to make sure
    client scripts are encapsulated with the if __name__ == '__main__' by
    our collegues running windows. Aka I expect to recieve this same bug
    report.
    I'll go through the docs again, but I didn't find any built-in way to
    get the recursion level of an operation (other than the 0 = __main__
    level).

    Looking like this just turned into a feature request.

    @acjames acjames mannequin added type-feature A feature request or enhancement and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Jun 1, 2009
    @jnoller
    Copy link
    Mannequin

    jnoller mannequin commented Jun 1, 2009

    Hey Alex; This isn't a bug, or a feature request. On win32, the way
    multiprocessing fakes a fork() is by creating a special subprocess which
    essentially imports and executes the function/process to be run,
    communication is handled through pickling and pipes.

    For more information, see:
    http://svn.python.org/view/python/trunk/Lib/multiprocessing/forking.py?
    view=markup

    Search for "# Windows" in that file, you'll see the basic process we use
    to "fork" on windows. Without a completely different implementation,
    this can not be changed. This probably will not change for some time, as
    such, I'm going to close this issue.

    @valhallasw
    Copy link
    Mannequin

    valhallasw mannequin commented Mar 10, 2012

    Two questions:
    (1) can this be at least be added as a big fat warning in the documentation?
    (2) would it be a reasonable option to let either
    (a) the creation of a Pool
    (b) executing something using the Pool
    cause an exception when it happens during the import of the function to run?

    I think it makes sense to prevent any accidental forkbombs, especially if they are /this/ easy to create. Untested (for obvious reasons...), but this should be enough:

    import multiprocessing
    def x(val):
       return val
    multiprocessing.Pool().map(x, range(10))

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    OS-windows type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant