Fixed for issue when sys.stdout.encoding is changing in runtime.