From 7fdcfbf34b189178ca83c42ee10fb98d88e7475f Mon Sep 17 00:00:00 2001
From: Paul McCarthy <pauld.mccarthy@gmail.com>
Date: Mon, 11 Jan 2016 17:45:57 +0000
Subject: [PATCH] I learned something new about python today. Module attributes
 can be GC'd before class instances - calls to log inside __del__ were bombing
 out.

---
 fsl/data/image.py                             | 3 ++-
 fsl/data/model.py                             | 3 ++-
 fsl/data/tensorimage.py                       | 3 ++-
 fsl/fsleyes/displaycontext/display.py         | 6 ++++--
 fsl/fsleyes/displaycontext/displaycontext.py  | 3 ++-
 fsl/fsleyes/editor/editor.py                  | 3 ++-
 fsl/fsleyes/editor/selection.py               | 3 ++-
 fsl/fsleyes/gl/globject.py                    | 3 ++-
 fsl/fsleyes/gl/shaders/arbp/program.py        | 3 ++-
 fsl/fsleyes/gl/shaders/glsl/program.py        | 3 ++-
 fsl/fsleyes/gl/textures/rendertexturestack.py | 3 ++-
 fsl/fsleyes/gl/textures/texture.py            | 3 ++-
 fsl/fsleyes/overlay.py                        | 2 --
 fsl/fsleyes/plotting/dataseries.py            | 3 ++-
 fsl/fsleyes/profiles/__init__.py              | 3 ++-
 15 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/fsl/data/image.py b/fsl/data/image.py
index 93c3b08e7..0ad84953f 100644
--- a/fsl/data/image.py
+++ b/fsl/data/image.py
@@ -351,7 +351,8 @@ class Image(Nifti1, props.HasProperties):
         
     def __del__(self):
         """Prints a log message. """
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
 
     def __hash__(self):
diff --git a/fsl/data/model.py b/fsl/data/model.py
index a336304ba..2d87e3947 100644
--- a/fsl/data/model.py
+++ b/fsl/data/model.py
@@ -71,7 +71,8 @@ class Model(object):
         
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
         
 
     def __repr__(self):
diff --git a/fsl/data/tensorimage.py b/fsl/data/tensorimage.py
index 5e7ba03f9..838910c8a 100644
--- a/fsl/data/tensorimage.py
+++ b/fsl/data/tensorimage.py
@@ -121,7 +121,8 @@ class TensorImage(fslimage.Nifti1):
 
         
     def __del__(self):
-        log.memory('{}.del({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del({})'.format(type(self).__name__, id(self)))
 
         
     def V1(self): return self.__v1
diff --git a/fsl/fsleyes/displaycontext/display.py b/fsl/fsleyes/displaycontext/display.py
index fcdbfdc0e..b85ae494c 100644
--- a/fsl/fsleyes/displaycontext/display.py
+++ b/fsl/fsleyes/displaycontext/display.py
@@ -175,7 +175,8 @@ class Display(props.SyncableHasProperties):
         
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
     
     def getOverlay(self):
@@ -421,7 +422,8 @@ class DisplayOpts(props.SyncableHasProperties, actions.ActionProvider):
         
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
         
     def destroy(self):
diff --git a/fsl/fsleyes/displaycontext/displaycontext.py b/fsl/fsleyes/displaycontext/displaycontext.py
index f52082a45..abc3ccb45 100644
--- a/fsl/fsleyes/displaycontext/displaycontext.py
+++ b/fsl/fsleyes/displaycontext/displaycontext.py
@@ -262,7 +262,8 @@ class DisplayContext(props.SyncableHasProperties):
         
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
         
     def destroy(self):
diff --git a/fsl/fsleyes/editor/editor.py b/fsl/fsleyes/editor/editor.py
index 6b145db99..5834e0611 100644
--- a/fsl/fsleyes/editor/editor.py
+++ b/fsl/fsleyes/editor/editor.py
@@ -138,7 +138,8 @@ class Editor(props.HasProperties):
 
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
         
     def destroy(self):
diff --git a/fsl/fsleyes/editor/selection.py b/fsl/fsleyes/editor/selection.py
index 231ee23af..431b7f354 100644
--- a/fsl/fsleyes/editor/selection.py
+++ b/fsl/fsleyes/editor/selection.py
@@ -124,7 +124,8 @@ class Selection(props.HasProperties):
 
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
 
 
diff --git a/fsl/fsleyes/gl/globject.py b/fsl/fsleyes/gl/globject.py
index 7acfd4215..3c03d030e 100644
--- a/fsl/fsleyes/gl/globject.py
+++ b/fsl/fsleyes/gl/globject.py
@@ -155,7 +155,8 @@ class GLObject(notifier.Notifier):
 
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
 
     def ready(self):
diff --git a/fsl/fsleyes/gl/shaders/arbp/program.py b/fsl/fsleyes/gl/shaders/arbp/program.py
index 47d868602..f82efed26 100644
--- a/fsl/fsleyes/gl/shaders/arbp/program.py
+++ b/fsl/fsleyes/gl/shaders/arbp/program.py
@@ -159,7 +159,8 @@ class ARBPShader(object):
 
     def __del__(self):
         """Prints a log message. """
-        log.memory('{}.del({})'.format(type(self).__name__, id(self))) 
+        if log:
+            log.memory('{}.del({})'.format(type(self).__name__, id(self))) 
         
 
     def destroy(self):
diff --git a/fsl/fsleyes/gl/shaders/glsl/program.py b/fsl/fsleyes/gl/shaders/glsl/program.py
index 118569acc..49275d54e 100644
--- a/fsl/fsleyes/gl/shaders/glsl/program.py
+++ b/fsl/fsleyes/gl/shaders/glsl/program.py
@@ -162,7 +162,8 @@ class GLSLShader(object):
         
     def __del__(self):
         """Prints a log message. """
-        log.memory('{}.del({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del({})'.format(type(self).__name__, id(self)))
 
             
     def load(self):
diff --git a/fsl/fsleyes/gl/textures/rendertexturestack.py b/fsl/fsleyes/gl/textures/rendertexturestack.py
index 6ed916c23..3d662c0d0 100644
--- a/fsl/fsleyes/gl/textures/rendertexturestack.py
+++ b/fsl/fsleyes/gl/textures/rendertexturestack.py
@@ -78,7 +78,8 @@ class RenderTextureStack(object):
         
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
         
     def destroy(self):
diff --git a/fsl/fsleyes/gl/textures/texture.py b/fsl/fsleyes/gl/textures/texture.py
index 6b97faabb..b30f3f38e 100644
--- a/fsl/fsleyes/gl/textures/texture.py
+++ b/fsl/fsleyes/gl/textures/texture.py
@@ -111,7 +111,8 @@ class Texture(object):
 
     def __del__(self):
         """Prints a log message."""
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
         
         
     def destroy(self):
diff --git a/fsl/fsleyes/overlay.py b/fsl/fsleyes/overlay.py
index 9ce3af588..f36c13ff4 100644
--- a/fsl/fsleyes/overlay.py
+++ b/fsl/fsleyes/overlay.py
@@ -288,8 +288,6 @@ def loadOverlays(paths, loadFunc='default', errorFunc='default', saveDir=True):
                     not an :class:`OverlayList`.
     """
 
-    defaultLoad = loadFunc == 'default'
-
     # The default load function updates
     # the dialog window created above
     def defaultLoadFunc(s):
diff --git a/fsl/fsleyes/plotting/dataseries.py b/fsl/fsleyes/plotting/dataseries.py
index 067d8ab48..ef086dda7 100644
--- a/fsl/fsleyes/plotting/dataseries.py
+++ b/fsl/fsleyes/plotting/dataseries.py
@@ -63,7 +63,8 @@ class DataSeries(props.HasProperties):
                    
     def __del__(self):
         """Prints a log message. """
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
 
     def destroy(self):
diff --git a/fsl/fsleyes/profiles/__init__.py b/fsl/fsleyes/profiles/__init__.py
index c0e8cbc36..34ba05edd 100644
--- a/fsl/fsleyes/profiles/__init__.py
+++ b/fsl/fsleyes/profiles/__init__.py
@@ -309,7 +309,8 @@ class Profile(props.SyncableHasProperties, actions.ActionProvider):
         
     def __del__(self):
         """Prints a log message. """
-        log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
+        if log:
+            log.memory('{}.del ({})'.format(type(self).__name__, id(self)))
 
                 
     def destroy(self):
-- 
GitLab