This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Steven.Barker
Recipients Steven.Barker
Date 2013-05-16.03:21:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1368674517.59.0.230555789399.issue17991@psf.upfronthosting.co.za>
In-reply-to
Content
While investigating a Stack Overflow question (http://stackoverflow.com/questions/16484764/multiprocessing-value-clear-syntax) I came across a misleading error message from the multiprocessing.Value constructor:

>>> import multiprocessing
>>> my_char = "x"
>>> v = multiprocessing.Value("c", my_char)
Traceback (most recent call last):
  File "<pyshell#21>", line 1, in <module>
    v = multiprocessing.Value("c", my_char)
  File "S:\Python33\lib\multiprocessing\__init__.py", line 243, in Value
    return Value(typecode_or_type, *args, lock=lock)
  File "S:\Python33\lib\multiprocessing\sharedctypes.py", line 70, in Value
    obj = RawValue(typecode_or_type, *args)
  File "S:\Python33\lib\multiprocessing\sharedctypes.py", line 47, in RawValue
    obj.__init__(*args)
TypeError: one character string expected

The "one character string expected" message was rather unhelpful, since that seemed to be what I gave it. After being stumped by this for a bit, I realized that it might be having an issue with Unicode and giving an error message more appropriate to Python 2 than Python 3. Sure enough, passing a one-character bytes instance works just fine.

So, at a minimum I think the error message should be updated to say it wants a one-character bytes instance rather than a "string" (which to my mind means a "str" instance). A further enhancement might be to accept unicode strings that contain just a single ASCII character too, but I realize that may be more messy and error prone.

The error message comes from the ctypes module, and can be reproduced easily:

>>> ctypes.c_char("x")
Traceback (most recent call last):
  File "<pyshell#28>", line 1, in <module>
    ctypes.c_char("x")
TypeError: one character string expected

The exception text comes from Modules/_ctypes/cfield.c:1151
History
Date User Action Args
2013-05-16 03:21:57Steven.Barkersetrecipients: + Steven.Barker
2013-05-16 03:21:57Steven.Barkersetmessageid: <1368674517.59.0.230555789399.issue17991@psf.upfronthosting.co.za>
2013-05-16 03:21:57Steven.Barkerlinkissue17991 messages
2013-05-16 03:21:56Steven.Barkercreate