smathot/OpenSesame — Issue #75: srbox not properly closed
Author: smathot
Created: 2012-02-14 12:39:26+00:00
State: open
Labels: Medium, Todo

Adding the following code to the prepare phase of an inline_script at the start of the experiment should fix the issue:

import types

def _close_srbox(self):

if hasattr(self.experiment, "srbox"):
# libsrbox is loaded as a property of experiment
# -> self.experiment.srbox
# The actual port is opened as a property of libsrbox
# -> self.experiment.srbox._srbox
self.experiment.srbox._srbox.close()
print "closing libsrbox"
else:
print "libsrbox not loaded"

# Add _close_srbox as method of the current object
self.close_srbox = types.MethodType(_close_srbox, self)

# Add it as a cleanup function, so it's called after the
# experiment
self.experiment.cleanup_functions.append(self.close_srbox)