Following code will crash with Python3 on PyCharm.
import locale
import logging
import logging.handlers
locale.setlocale(locale.LC_ALL, 'de_CH.UTF-8')
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
logger = logging.getLogger(__name__)
logger.addHandler(stream_handler)
logger.error('testing')
The code should print testing
.
PyCharm will crash and print the exit code:
Python crashes with 'Process finished with exit code -1073740940 (0xC0000374)'
Tested under Windows 10 - 10.0.17134 Build 17134, Python 3.6.3.
I've also tested it under Windows CMD with:
c:\Python361\python.exe -c "import locale; import logging; import logging.handlers; locale.setlocale(locale.LC_ALL, 'de_CH.UTF-8'); stream_handler = logging.StreamHandler(); stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')); logger = logging.getLogger(__name__); logger.addHandler(stream_handler); logger.error('testing')"
Which should print testing
but ends without any output. I have also test it with Python 3.7.3 on the Windows CMD with the same result.
I've also tested the code with Python 3.6.1 on IDLE:
import locale; import logging; import logging.handlers; locale.setlocale(locale.LC_ALL, 'de_CH.UTF-8'); stream_handler = logging.StreamHandler(); stream_handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')); logger = logging.getLogger(__name__); logger.addHandler(stream_handler); logger.error('testing')
Which prints
'de_CH.UTF-8'
=============================== RESTART: Shell ===============================
I've found a solution following the python issue page here
https://bugs.python.org/issue36792#msg342966
Changing
locale.setlocale(locale.LC_ALL, 'de_CH.UTF-8')
to
locale.setlocale(locale.LC_ALL, 'de-CH')
solves the problem.
User contributions licensed under CC BY-SA 3.0