dschreij/OpenSesame — pull request #2 by smathot (2013-06-29 15:31:36+00:00)
Title: Add runner option to config

I took a look at the `inline_script` error, and I'm not sure what's going on either yet. But looking at the code, I think some serious clean-up is needed first, before we start hacking on this specific error. (That's not a criticism of your code, this part of the code was a mess to begin with.) Right now there is no systematic way in which exceptions are handled, and its very difficult to follow the logic of how the experiment is started.

I was thinking about something like the following: For each method for running an experiment, we create a `runner` object. These runners receive an experiment object, execute it, and return the exception or None if no exception occurred. The runners should hold their own, so they should end and clean up the experiment themselves. So from the perspective of the GUI there is no difference between the multiprocess runner, the original (inprocess) runner, or the external (opensesamerun) runner. They are just runners that take an experiment and return the results.

~~~ .python
class multiprocess_runner(object):

def __init__(self, main_window, experiment, fullscreen=True):

# Constructor

def execute(self):

"""
Executes the experiment.

Returns:
None if the experiment stopped cleanly, an Exception otherwise.
"""

# Execution code. This should be transparent for the rest for
# OpenSesame. The experiment should always be ended cleanly, also if an
# exception occurred. In the case of opensesamerun (external_runner),
# the exception may be handled by the opensesamerun, in which case None
# is always returned. But if remotely possible, the exception should be
# returned and handle by the GUI.
~~~

Everything that is not specific to the runner is implemented in `qtopensesame.run_experiment()`, which can be simplified considerably.

~~~ .python
def run_experiment(self, dummy=None, fullscreen=True, quick=False):

# Handle stuff that needs to be done regardless of the runner
# - Disable GUI
# - Create experiment object
# - Reroute stdout to debug window
# - Pause auto-save timer

if config.runner = u'multiprocess':
from libqtopensesame.runner import multiprocess_runner as runner
elif config.runner = u'inprocess':
from libqtopensesame.runner import inprocess_runner as runner
config.runner = u'external':
from libqtopensesame.runner import external_runner as runner

exception = runner(self, exp, fullscreen=fullscreen).execute()
if exception != None:
# Inform the user that an exception occurred

# Restore everything
# - Enable GUI
# - Create experiment object
# - Restore stdout
# - Resume auto-save timer
# - Ask to save logfile in filepool

~~~

What do you think?