Python: using a specific date format in a logger Formatter crashes Blender on Windows #50021

Closed
opened 2016-11-14 10:33:17 +01:00 by Rainer Trummer · 18 comments

I've started working with logging thanks to Sybrens presentation at BCon16. Today, I ran into a strange issue. On Linux, the code below works as expected, and gives me (what I think) nicely formatted log messages. However, on Windows, Blender (2.78a) closes immediately.

Now the strange part: If you remove the following part of the code below, the formatter works fine on Windows too:datefmt = '%D.%M.%Y, %H:%M:%S'
It seems like something in this formatting code causes a complete Blender shutdown, and only on Windows.

This is the full code, it can be run from a Blender Text Editor:

import logging, os

#    prepare a logger
def get_logger():
	#    add a logger and set it to Debug level (for the file handler)
	__logger__ = logging.getLogger(__package__)
	__logger__.setLevel(logging.DEBUG)

	- TODO: the formatter crashes Blender on Windows
	- it happens when trying to use a date format
	_formatter = logging.Formatter(fmt = '%(levelname)-8s | %(asctime)s | %(name)s.%(module)s, line %(lineno)d \n           %(message)s\n', datefmt = '%D.%M.%Y, %H:%M:%S')

	_streamHandler = logging.StreamHandler()
	_streamHandler.setFormatter(_formatter)
	_streamHandler.setLevel(logging.WARNING)
	__logger__.addHandler(_streamHandler)

	try:
		_handler = logging.FileHandler(os.path.expanduser("~/%s.txt" % __package__), mode = 'w')
		_handler.setFormatter(_formatter)
		__logger__.addHandler(_handler)
	except Exception as exc:
		__logger__.error('could not initialize file logging: %s' % exc)

	__logger__.info('logger initialized')

	return __logger__

__logger__ = get_logger()

OS Windows 7, 64 bit, crashing
OS Ubuntu Gnome 16.04, working fine

I've started working with logging thanks to Sybrens presentation at BCon16. Today, I ran into a strange issue. On Linux, the code below works as expected, and gives me (what I think) nicely formatted log messages. However, on Windows, Blender (2.78a) closes immediately. Now the strange part: If you remove the following part of the code below, the formatter works fine on Windows too:**datefmt = '%D.%M.%Y, %H:%M:%S'** It seems like something in this formatting code causes a complete Blender shutdown, and only on Windows. This is the full code, it can be run from a Blender Text Editor: ``` import logging, os # prepare a logger def get_logger(): # add a logger and set it to Debug level (for the file handler) __logger__ = logging.getLogger(__package__) __logger__.setLevel(logging.DEBUG) - TODO: the formatter crashes Blender on Windows - it happens when trying to use a date format _formatter = logging.Formatter(fmt = '%(levelname)-8s | %(asctime)s | %(name)s.%(module)s, line %(lineno)d \n %(message)s\n', datefmt = '%D.%M.%Y, %H:%M:%S') _streamHandler = logging.StreamHandler() _streamHandler.setFormatter(_formatter) _streamHandler.setLevel(logging.WARNING) __logger__.addHandler(_streamHandler) try: _handler = logging.FileHandler(os.path.expanduser("~/%s.txt" % __package__), mode = 'w') _handler.setFormatter(_formatter) __logger__.addHandler(_handler) except Exception as exc: __logger__.error('could not initialize file logging: %s' % exc) __logger__.info('logger initialized') return __logger__ __logger__ = get_logger() ``` **OS** Windows 7, 64 bit, *crashing* **OS** Ubuntu Gnome 16.04, *working fine*
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @RainerTrummer

Added subscriber: @RainerTrummer

Added subscriber: @mont29

Added subscriber: @mont29

Please try to reproduce this issue with vanilla python 3.6 for windows, this totaly sounds like python bug, not Blender bug…

Please try to reproduce this issue with vanilla python 3.6 for windows, this totaly sounds like python bug, not Blender bug…

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Bastien Montagne self-assigned this 2016-12-02 10:07:12 +01:00

More than a week without reply. Due to the policy of the tracker archiving for until required info/data are provided.

More than a week without reply. Due to the policy of the tracker archiving for until required info/data are provided.
Author

Wasn't able to reply before as client projects kept me busy, sorry for the inconvenience.

Tried with Vanilla Python today, version 3.5.2, on the same machine where Blender crashes. Created both a file handler and stream handler for the logger, set the formatting as before, tried logging, all from interactive console. NO crash there.

Log output as desired:
output.JPG

Formatter used:
formatter.JPG

Wasn't able to reply before as client projects kept me busy, sorry for the inconvenience. Tried with Vanilla Python today, version 3.5.2, on the same machine where Blender crashes. Created both a file handler and stream handler for the logger, set the formatting as before, tried logging, all from interactive console. NO crash there. Log output as desired: ![output.JPG](https://archive.blender.org/developer/F412985/output.JPG) Formatter used: ![formatter.JPG](https://archive.blender.org/developer/F412984/formatter.JPG)

Changed status from 'Archived' to: 'Open'

Changed status from 'Archived' to: 'Open'

Hmm… we are going to update to py3.5.2 in coming days, but so far Blender was released with py3.5.1, and 3.5.2 seems to include some datetime fixes. So can try to confirm issue is not reproducible with vanilla py3.5.1 under windows as well?

Hmm… we are going to update to py3.5.2 in coming days, but so far Blender was released with py3.5.1, and 3.5.2 seems to include some datetime fixes. So can try to confirm issue is not reproducible with vanilla py3.5.1 under windows as well?

Added subscriber: @VukGardasevic

Added subscriber: @VukGardasevic

Can you also check if the Experimental VS 2015 builds from https://builder.blender.org/download/ crash for you?

Can you also check if the Experimental VS 2015 builds from https://builder.blender.org/download/ crash for you?
Author

@VukGardasevic I've tested a version which I compiled on the 23rd of November (reports as 2.78.4), it crashes, but with some more latency. Testing VS2015 build, downloaded right now: WORKS! no crashes there!

@VukGardasevic I've tested a version which I compiled on the 23rd of November (reports as 2.78.4), it crashes, but with some more latency. Testing VS2015 build, downloaded right now: WORKS! no crashes there!
Member

Added subscriber: @LazyDodo

Added subscriber: @LazyDodo
Member

I'm in the process of upgrading the windows libs, unless something unexpected causes issues the 3.5.2 libs should be available in the next few days.

I'm in the process of upgrading the windows libs, unless something unexpected causes issues the 3.5.2 libs should be available in the next few days.
Author

@mont29 HEAD BUMP You can close the report I guess. For one, the crash doesn't appear in newer Python versions, but further more my date format was nonsense. The formatter should have been:

_formatter = logging.Formatter(fmt = '%(levelname)-8s | %(asctime)s | %(name)s.%(module)s, line %(lineno)d \n %(message)s\n', datefmt='%d.%m.%Y, %H:%M:%S')

In other words: Instead of:

datefmt='%D.%M.%Y, %H:%M:%S'

which I had passed on initially, it should read:

datefmt='%d.%m.%Y, %H:%M:%S'

I was passing the Minutes-Variable twice (%M is Minutes, not the Month), and the %D variable (which might be the var for the full date). Not sure why the crash didn't happen on Linux, but I think everything should be safe.

@mont29 **HEAD BUMP** You can close the report I guess. For one, the crash doesn't appear in newer Python versions, but further more my date format was nonsense. The formatter should have been: _formatter = logging.Formatter(fmt = '%(levelname)-8s | %(asctime)s | %(name)s.%(module)s, line %(lineno)d \n %(message)s\n', datefmt='%d.%m.%Y, %H:%M:%S') In other words: Instead of: datefmt='**%D.%M.%Y**, %H:%M:%S' which I had passed on initially, it should read: datefmt='**%d.%m.%Y**, %H:%M:%S' I was passing the Minutes-Variable twice (%M is **M**inutes, not the **M**onth), and the %D variable (which might be the var for the full date). Not sure why the crash didn't happen on Linux, but I think everything should be safe.

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'

Oki, then let’s consider this as settled for now (we can always reopen should the issue arise again with newest libs & builds). ;)

Oki, then let’s consider this as settled for now (we can always reopen should the issue arise again with newest libs & builds). ;)
Member

Updated libs to python 3.5.2 , issue remains on the vc2013 builds, the crash is coming out of the ms c runtime though, not sure what we could do about it, it's pretty much how wcsftime deals with a bad formatter, best advise is not to use a bad formatter.

Updated libs to python 3.5.2 , issue remains on the vc2013 builds, the crash is coming out of the ms c runtime though, not sure what we could do about it, it's pretty much how wcsftime deals with a bad formatter, best advise is not to use a bad formatter.
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#50021
No description provided.