[Bf-committers] Python console IO encoding: PYTHONIOENCODING envvar

Brecht Van Lommel brechtvanlommel at pandora.be
Mon Sep 16 13:49:58 CEST 2013


Can we recompile our Python libraries on Windows with your patch to
add PyOS_PutEnv?

It's annoying to patch our libraries but it's also a quite serious bug.

On Mon, Sep 16, 2013 at 12:46 PM, Campbell Barton <ideasman42 at gmail.com> wrote:
> While its good you found a solution for this case my main concern is
> that we still have many other areas that print files or show filepaths
> in the UI, so you can close one bug but others will be reported.
>
> Basically if you were to apply this fix to Blender all over, it would
> be a much larger patch.
>
> I had a fix that replaced sys.stdout with one that had different
> encoding, it worked well *except* it crashed on exit for debug builds
> in windows (some file resource management assert caused by overwriting
> stdout).
>
> I was hoping Python devs would provide a solution by next release, but
> theres no activity on the bug report to indicate that.
>
> We could also just investigate a better hack for sys.stdout to force
> it to be the encoding we want and avoid having to add workarounds all
> over our python scripts.
> For now this is my preference since at least the change is in one
> place and we don't have to worry about adding safe_print's to addons
> etc.
>
>
> Note, its not good practice to modify kwargs, you can do this instead.
>  print(*args, file=sys.stderr, **kwargs)
>
>
> On Mon, Sep 16, 2013 at 5:27 PM, Bastien Montagne <montagne29 at wanadoo.fr> wrote:
>> Well, in the bug report error comes from a print in addon_utils.py...
>> Here is a patch (small wrapper around print that sets 'file' kwarg to
>> sys.stderr) that fixes the issue, at least for me (tested with an ascii
>> console): http://www.pasteall.org/45600/diff
>>
>> On 16/09/2013 08:40, Campbell Barton wrote:
>>> On Mon, Sep 16, 2013 at 4:17 PM, Bastien Montagne<montagne29 at wanadoo.fr>  wrote:
>>>> Hi Campbell,
>>>>
>>>> Could we consider using stderr in these cases, as a temp workaround?
>>>>   From doc, "For stderr, the :errorhandler part is ignored; the handler
>>>> will always be 'backslashreplace'.", and indeed a quick test (under
>>>> linux) prints escapes codes in an ASCII console, instead of erroring...
>>> Ah nice, I wasn't aware of this,
>>> however I think using the stderr isn't going to be able to resolve all
>>> these issues.
>>>
>>> print() can be replaced with sys.stderr.write(), but in the bug report
>>> the error is in %r ->  repr(). which makes a string to pass to Blenders
>>> UI.
>>> So not sure how stderr would be used to get around this.
>>>
>>>> On 14/09/2013 02:40, Campbell Barton wrote:
>>>>> On Fri, Sep 13, 2013 at 11:02 PM, Bastien Montagne
>>>>> <montagne29 at wanadoo.fr>   wrote:
>>>>>> Hey devs,
>>>>>>
>>>>>> Just ran into this bug report:
>>>>>> https://projects.blender.org/tracker/?func=detail&atid=498&aid=36722&group_id=9
>>>>>>
>>>>>> Most likely, it is an issue of non-encodable char in its path (stupid
>>>>>> windows...)
>>>>>>
>>>>>> Anyway, searching a bit around, I found PYTHONIOENCODING envvar
>>>>>> (http://docs.python.org/3/using/cmdline.html#envvar-PYTHONIOENCODING),
>>>>>> which is supposed to force encoding of stdXXX streams. Are we already
>>>>>> using this, or wouldn't it work in our case? Else, setting it to
>>>>>> something like "utf-8:replace" could save us some issues under windows...
>>>>> Afraid its a known issue, see comment in BPY_python_start():
>>>>> 'PYTHONIOENCODING' is ignored in MS-Windows
>>>>>
>>>>> bug report:
>>>>> https://projects.blender.org/tracker/?func=detail&aid=31555
>>>>>
>>>>> upstream report to CPython:
>>>>> http://bugs.python.org/issue16129
>>>>>
>>>> _______________________________________________
>>>> Bf-committers mailing list
>>>> Bf-committers at blender.org
>>>> http://lists.blender.org/mailman/listinfo/bf-committers
>>>
>>>
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-committers
>
>
>
> --
> - Campbell
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers


More information about the Bf-committers mailing list