@app.route("<STR_LIT>", methods=["<STR_LIT:POST>"])<EOL>def launch():
try:<EOL><INDENT>exp = Experiment(db.init_db(drop_all=False))<EOL><DEDENT>except Exception as ex:<EOL><INDENT>return error_response(<EOL>error_text="<STR_LIT>".format(str(ex)),<EOL>status=<NUM_LIT>,<EOL>simple=True,<EOL>)<EOL><DEDENT>try:<EOL><INDENT>exp.log("<STR_LIT>", "<STR_LIT>")<EOL><DEDENT>except IOError as ex:<EOL><INDENT>return error_response(<EOL>error_text="<STR_LIT>".format(str(ex)),<EOL>status=<NUM_LIT>,<EOL>simple=True,<EOL>)<EOL><DEDENT>try:<EOL><INDENT>recruitment_details = exp.recruiter.open_recruitment(<EOL>n=exp.initial_recruitment_size<EOL>)<EOL>session.commit()<EOL><DEDENT>except Exception as e:<EOL><INDENT>return error_response(<EOL>error_text="<STR_LIT>"<EOL>"<STR_LIT>".format(str(e)),<EOL>status=<NUM_LIT>,<EOL>simple=True,<EOL>)<EOL><DEDENT>for task in exp.background_tasks:<EOL><INDENT>try:<EOL><INDENT>gevent.spawn(task)<EOL><DEDENT>except Exception:<EOL><INDENT>return error_response(<EOL>error_text="<STR_LIT>".format(task)<EOL>+ "<STR_LIT>",<EOL>status=<NUM_LIT>,<EOL>simple=True,<EOL>)<EOL><DEDENT><DEDENT>if _config().get("<STR_LIT>", False):<EOL><INDENT>try:<EOL><INDENT>task = ReplayBackend(exp)<EOL>gevent.spawn(task)<EOL><DEDENT>except Exception:<EOL><INDENT>return error_response(<EOL>error_text="<STR_LIT>"<EOL>"<STR_LIT>",<EOL>status=<NUM_LIT>,<EOL>simple=True,<EOL>)<EOL><DEDENT><DEDENT>if exp.channel is not None:<EOL><INDENT>try:<EOL><INDENT>from dallinger.experiment_server.sockets import chat_backend<EOL>chat_backend.subscribe(exp, exp.channel)<EOL><DEDENT>except Exception:<EOL><INDENT>return error_response(<EOL>error_text="<STR_LIT>"<EOL>+ "<STR_LIT:{}>".format(exp.channel)<EOL>+ "<STR_LIT>",<EOL>status=<NUM_LIT>,<EOL>simple=True,<EOL>)<EOL><DEDENT><DEDENT>message = "<STR_LIT:\n>".join(<EOL>(<EOL>"<STR_LIT>".format(<EOL>"<STR_LIT:\n>".join(recruitment_details["<STR_LIT>"])<EOL>),<EOL>"<STR_LIT>".format(recruitment_details["<STR_LIT:message>"]),<EOL>)<EOL>)<EOL>return success_response(recruitment_msg=message)<EOL>
Launch the experiment.