[New-bugs-announce] [issue30379] multiprocessing Array create for ctypes.c_char, TypeError unless 1 char string arg used

John Schaefer report at bugs.python.org
Tue May 16 10:58:51 EDT 2017


New submission from John Schaefer:

When creating a multiprocessing Array equivalent for unsigned chars, eg from a numpy.uint8 array, the first argument: typecode_or_type must be specified as a one character string, if a typecode is used the method raises a TypeError.

>>> import numpy as np, multiprocessing as mp, ctypes
>>> arr = np.array(range(10), dtype=np.uint8)
>>> arr
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=uint8)
>>> mp.Array("B", arr)
<SynchronizedArray wrapper for <multiprocessing.sharedctypes.c_ubyte_Array_10 object
>>> mp.Array(ctypes.c_char, arr)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/multiprocessing/__init__.py", line 260, in Array
    return Array(typecode_or_type, size_or_initializer, **kwds)
  File "/usr/lib/python2.7/multiprocessing/sharedctypes.py", line 120, in Array
    obj = RawArray(typecode_or_type, size_or_initializer)
  File "/usr/lib/python2.7/multiprocessing/sharedctypes.py", line 94, in RawArray
    result.__init__(*size_or_initializer)
TypeError: one character string expected

This contrasts with behavior exhibited with other types:
>>> farr = np.array(range(10), dtype=np.float)
>>> mp.Array(ctypes.c_double, farr)
<SynchronizedArray wrapper...

thanks, John

----------
messages: 293765
nosy: jgschaefer
priority: normal
severity: normal
status: open
title: multiprocessing Array create for ctypes.c_char, TypeError unless 1 char string arg used
type: behavior
versions: Python 2.7

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


More information about the New-bugs-announce mailing list