[New-bugs-announce] [issue15901] multiprocessing sharedctypes Array don't accept strings

Simon R report at bugs.python.org
Mon Sep 10 11:59:39 CEST 2012


New submission from Simon R:

I've simply tested the example reported in the py3k documentation, and it don't works.

See the site:
http://docs.python.org/py3k/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing.sharedctypes

The program exit with this error:

> python sha.py
Traceback (most recent call last):
  File "sha.py", line 21, in <module>
    s = Array('c', 'hello world', lock=lock)
  File "/usr/lib/python3.2/multiprocessing/sharedctypes.py", line 112, in Array
    obj = RawArray(typecode_or_type, size_or_initializer)
  File "/usr/lib/python3.2/multiprocessing/sharedctypes.py", line 89, in RawArray
    result.__init__(*size_or_initializer)
TypeError: one character string expected


Observe that the following code works correctly with python2!

I'm using python 3.2.3 and gcc 4.7.1 under ArchLinx 
 
Te code is:

http://docs.python.org/py3k/library/multiprocessing.html?highlight=multiprocessing#module-multiprocessing.sharedctypes

####################################################################

from multiprocessing import Process, Lock
from multiprocessing.sharedctypes import Value, Array
from ctypes import Structure, c_double

class Point(Structure):
    _fields_ = [('x', c_double), ('y', c_double)]

def modify(n, x, s, A):
    n.value **= 2
    x.value **= 2
    s.value = s.value.upper()
    for a in A:
        a.x **= 2
        a.y **= 2

if __name__ == '__main__':
    lock = Lock()

    n = Value('i', 7)
    x = Value(c_double, 1.0/3.0, lock=False)
    s = Array('c', 'hello world', lock=lock)
    A = Array(Point, [(1.875,-6.25), (-5.75,2.0), (2.375,9.5)], lock=lock)

    p = Process(target=modify, args=(n, x, s, A))
    p.start()
    p.join()

    print((n.value))
    print((x.value))
    print((s.value))
    print([(a.x, a.y) for a in A])

----------
components: ctypes
messages: 170171
nosy: bred
priority: normal
severity: normal
status: open
title: multiprocessing sharedctypes Array don't accept strings
type: crash
versions: Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15901>
_______________________________________


More information about the New-bugs-announce mailing list