Skip to content


Browse files Browse the repository at this point in the history
BF: some machines weren't saving data correctly mid-experiment
Must have been something to do with ExperimentHandler not cleaning itself
up (maybe due to a circular reference somewhere?)

Adding the use of atexit as a second safety measure but keeping __del__
as well.

This commit is taking the code from
but can't cherry-pick those due to restructured code
  • Loading branch information
peircej committed Dec 7, 2017
1 parent c555ca2 commit 193ce54
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions psychopy/
Expand Up @@ -18,6 +18,7 @@
from scipy import optimize, special
import inspect # so that Handlers can find the script that called them
import codecs
import atexit
import weakref
import re
import warnings
Expand Down Expand Up @@ -112,6 +113,7 @@ def __init__(self,
autoLog : True (default) or False
self.loops = []
self.loopsUnfinished = [] = name
Expand All @@ -137,16 +139,11 @@ def __init__(self,
# fail now if we fail at all!
checkValidFilePath(dataFileName, makeValid=True)
# make sure we close and save data when Python exits

def __del__(self):
if self.dataFileName not in ['', None]:
if self.autoLog:
'Saving data for %s ExperimentHandler' %
if self.savePickle == True:
if self.saveWideText == True:
self.saveAsWideText(self.dataFileName + '.csv', delim=',')

def addLoop(self, loopHandler):
"""Add a loop such as a :class:``
Expand Down Expand Up @@ -377,6 +374,23 @@ def saveAsPickle(self, fileName, fileCollisionMethod='rename'):
self.savePickle = savePickle
self.saveWideText = saveWideText

def close(self):
"""Cleanly close the experiment and save files if needed.
This method isn't usually needed by the user - it is called at exit
by the Python instance
if self.dataFileName not in ['', None]:
if self.autoLog:
logging.debug(u'Saving data for %s ExperimentHandler'
if self.savePickle:
if self.saveWideText:
self.saveAsWideText(self.dataFileName + '.csv', delim=',')
self.autoLog = False

def abort(self):
"""Inform the ExperimentHandler that the run was aborted.
Expand Down

0 comments on commit 193ce54

Please sign in to comment.