Unregister not called on shutdown

Has anyone ever noticed that while the unregister method is called when disabling a module, it is not called on shutdown?
Under some circumstances, this behavior is less problematic because the (or a) destructor would be triggered anyway, but this does not apply in general, e.g. when there is still a thread running in the background.

Regarding multi threading, there is some information here, but the issue I am facing is different:
As there is a thread running in the background, python first waits for the thread to exit. I have no handler to indicate that blender wants to quit and hence it will wait forever.

I have seen a bug report on a similar topic with ambiguous answers. Has anyone had similar problems and maybe found a solution? Always having to disable the module before being able to quit is not really acceptable :wink:

Here is a minimal example:


bl_info = {
	"name": "test",
	"author": "foo bar",
	"version": (0, 0),
	"blender": (2, 6, 2),
	"location": "Info header, render engine menu",
	"description": "bug demonstration",
	"warning": "",
	"wiki_url": "",
	"tracker_url": "",
	"category": "Render"}


import threading


run = False
aThread = None


def mythread():
	global run
	while run:
		print("x")


def register():
	print("REGISTER")
	global aThread
	global run
	run = True
	aThread = threading.Thread(target=mythread)
	aThread.start()


def unregister():	
	print("UNREGISTER")
	global run
	run = False


If you disable the module you can close blender, otherwise it gets stuck waiting for the thread to finish.

Well, it works as intended:

https://developer.blender.org/T37021

It’s not very nice and somewhat unexpected, and apparantly no way to add a callback like an app handler quit_pre (although I could swear a saw a commit like that added it, or it was just late and i’m already dreaming…)

This is exactly the bug report I was referring to, but we are not talking about the same issue. The bug report is about running a script and I am talking about a addon module. The answer given there (“When an addon is unloaded it’s unregister function will be called”) is wrong in the sense that closing blender does not unload modules, what my example clearly proves.

As this behavior can hardly be intentional, it must be a bug.

@CoDEmanX: If you agree, could you submit this bug? Otherwise I’d have to create an account just for this one issue…