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 Array and sharedctypes.Array error in docs/implementation #47456

Closed
mishok13 mannequin opened this issue Jun 26, 2008 · 5 comments
Closed

Multiprocessing Array and sharedctypes.Array error in docs/implementation #47456

mishok13 mannequin opened this issue Jun 26, 2008 · 5 comments
Labels
docs Documentation in the Doc dir stdlib Python modules in the Lib dir

Comments

@mishok13
Copy link
Mannequin

mishok13 mannequin commented Jun 26, 2008

BPO 3206
Nosy @birkenfeld
Superseder
  • bpo-4449: AssertionError in Doc/includes/mp_benchmarks.py
  • Files
  • multiprocessing.diff
  • 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 2008-12-08.16:13:53.453>
    created_at = <Date 2008-06-26.09:53:16.463>
    labels = ['library', 'docs']
    title = 'Multiprocessing Array and sharedctypes.Array error in docs/implementation'
    updated_at = <Date 2008-12-08.17:03:05.126>
    user = 'https://bugs.python.org/mishok13'

    bugs.python.org fields:

    activity = <Date 2008-12-08.17:03:05.126>
    actor = 'amaury.forgeotdarc'
    assignee = 'jnoller'
    closed = True
    closed_date = <Date 2008-12-08.16:13:53.453>
    closer = 'jnoller'
    components = ['Documentation', 'Library (Lib)']
    creation = <Date 2008-06-26.09:53:16.463>
    creator = 'mishok13'
    dependencies = []
    files = ['10741']
    hgrepos = []
    issue_num = 3206
    keywords = ['patch']
    message_count = 5.0
    messages = ['68771', '68772', '77121', '77123', '77319']
    nosy_count = 5.0
    nosy_names = ['georg.brandl', 'sgala', 'roudkerk', 'jnoller', 'mishok13']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '4449'
    type = None
    url = 'https://bugs.python.org/issue3206'
    versions = ['Python 3.0']

    @mishok13
    Copy link
    Mannequin Author

    mishok13 mannequin commented Jun 26, 2008

    multiprocessing.sharedctypes.Array and
    multiprocessing.sharedctypes.Value if used according to documentation
    fail with AssertionError.

    Python 3.0b1+ (py3k:64518, Jun 25 2008, 12:52:38)
    [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from multiprocessing import sharedctypes
    >>> sharedctypes.Array('i', 1, lock=True)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.0/multiprocessing/sharedctypes.py", line
    88, in Array
    assert hasattr(lock, 'acquire')
    AssertionError
    >>> sharedctypes.Array('i', 1, lock=False)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.0/multiprocessing/sharedctypes.py", line
    88, in Array
    assert hasattr(lock, 'acquire')
    AssertionError
    >>> sharedctypes.Array('i', 1, lock=None)
    <SynchronizedArray wrapper for
    <multiprocessing.sharedctypes.c_long_Array_1 object at 0x83214f4>>
    >>> Value('i', lock=True)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.0/multiprocessing/__init__.py", line 246,
    in Value
    return Value(typecode_or_type, *args, **kwds)
      File "/usr/local/lib/python3.0/multiprocessing/sharedctypes.py", line
    75, in Value
    assert hasattr(lock, 'acquire')
    AssertionError

    The same goes for multiprocessing.Array and multiprocessing.Value.

    Comparing code to documentation it's obvious that lock argument can be
    one of Lock, RLock or None objects (or any object with "acquire"
    attribute), but not True or False. Also, looking at the code it seems
    strange to me that 'lock' is a keyword-only argument. Why not use simple
    default argument "lock=None" for Array() function?
    Proposed patch tries to address these issues.

    @mishok13 mishok13 mannequin added stdlib Python modules in the Lib dir docs Documentation in the Doc dir labels Jun 26, 2008
    @mishok13 mishok13 mannequin assigned birkenfeld Jun 26, 2008
    @mishok13
    Copy link
    Mannequin Author

    mishok13 mannequin commented Jun 26, 2008

    And here is the patch itself. :)

    @benjaminp benjaminp assigned jnoller and unassigned birkenfeld Jun 26, 2008
    @sgala
    Copy link
    Mannequin

    sgala mannequin commented Dec 6, 2008

    Note that if the error is in the documentation semantics, and not in the
    implementation, then the benchmark code in the documentation is also
    broken, and should be change to not use lock=True/False respectively...

    I'm not sure if the patch here is good or rather lock=True/False should
    be the right API and the implementation should be changed along this lines:

    diff --git a/Lib/multiprocessing/sharedctypes.py
    b/Lib/multiprocessing/sharedctypes.py
    index b94cd52..2f68e74 100644
    --- a/Lib/multiprocessing/sharedctypes.py
    +++ b/Lib/multiprocessing/sharedctypes.py
    @@ -79,10 +79,11 @@ def Array(typecode_or_type, size_or_initializer,
    **kwds):
         if kwds:
             raise ValueError('unrecognized keyword argument(s): %s' %
    list(kwds.keys()))
         obj = RawArray(typecode_or_type, size_or_initializer)
    -    if lock is None:
    +    if lock is True:
             lock = RLock()
    -    assert hasattr(lock, 'acquire')
    -    return synchronized(obj, lock)
    +        return synchronized(obj, lock)
    +    return obj
    +    
     
     def copy(obj):
         new_obj = _new_value(type(obj))

    @sgala
    Copy link
    Mannequin

    sgala mannequin commented Dec 6, 2008

    oops, there is a proper code patch in bpo-4449 , and the documentation
    is right.

    @jnoller jnoller mannequin closed this as completed Dec 8, 2008
    @jnoller
    Copy link
    Mannequin

    jnoller mannequin commented Dec 8, 2008

    Dupe, bpo-4449

    @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
    docs Documentation in the Doc dir stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant