def start(self, runName, model, recorder, *args, **kwargs) :
		"""Starts the training and encapsulates it into a safe environement.
		If the training stops because of an Exception or SIGTEM, the trainer
		will save logs, the store, and the last version of the model.
		"""

		import simplejson, signal, cPickle

		def _handler_sig_term(sig, frame) :
			_dieGracefully("SIGTERM", None)
			sys.exit(sig)

		def _dieGracefully(exType, tb = None) :
			if type(exType) is types.StringType :
				exName = exType
			else :
				exName = exType.__name__

			death_time = time.ctime().replace(' ', '_')
			filename = "dx-xb_" + runName + "_death_by_" + exName + "_" + death_time
			sys.stderr.write("\n===\nDying gracefully from %s, and saving myself to:\n...%s\n===\n" % (exName, filename))
			model.saveParameters(filename)
			f = open(filename +  ".traceback.log", 'w')
			f.write("Mariana training Interruption\n=============================\n")
			f.write("\nDetails\n-------\n")
			f.write("Name: %s\n" % runName)
			f.write("pid: %s\n" % os.getpid())
			f.write(str(exType) % "Killed by: %s\n")
			f.write("Time of death: %s\n" % death_time)
			f.write("Model saved to: %s\n" % filename)
			sstore = str(self.store).replace("'", '"').replace("True", 'true').replace("False", 'false')
			try :
				f.write(
					"store:\n%s" % json.dumps(
						json.loads(sstore), sort_keys=True,
						indent=4,
						separators=(',', ': ')
					)
				)
			except ValueError :
				print "invalid json", sstore

			if tb is not None :
				f.write("\nTraceback\n---------\n")
				f.write(str(traceback.extract_tb(tb)).replace("), (", "),\n(").replace("[(","[\n(").replace(")]",")\n]"))
			f.flush()
			f.close()
			f = open(filename + ".store.pkl", "wb")
			cPickle.dump(self.store, f)
			f.close()

		signal.signal(signal.SIGTERM, _handler_sig_term)
		if MSET.VERBOSE :
			print "\n" + "Training starts."		
		MCAN.friendly("Process id", "The pid of this run is: %d" % os.getpid())

		if recorder == "default" :
			params = {
				"printRate" : 1,
				"writeRate" : 1
			}
			recorder = MREC.GGPlot2(runName, **params)
			MCAN.friendly(
				"Default recorder",
				"The trainer will recruit the default 'GGPlot2' recorder with the following arguments:\n\t %s.\nResults will be saved into '%s'." % (params, recorder.filename)
			)
	
		if not self.saveIfMurdered :
			return self.run(runName, model, recorder, *args, **kwargs)
		else :
			try :
				return self.run(runName, model, recorder, *args, **kwargs)
			except MSTOP.EndOfTraining as e :
				print e.message
				death_time = time.ctime().replace(' ', '_')
				filename = "finished_" + runName +  "_" + death_time
				f = open(filename +  ".stopreason.txt", 'w')
				f.write("Name: %s\n" % runName)
				f.write("pid: %s\n" % os.getpid())
				f.write("Time of death: %s\n" % death_time)
				f.write("Epoch of death: %s\n" % self.store["runInfos"]["epoch"])
				f.write("Stopped by: %s\n" % e.stopCriterion.name)
				f.write("Reason: %s\n" % e.message)
				sstore = str(self.store).replace("'", '"').replace("True", 'true').replace("False", 'false')
				f.write(
					"store:\n%s" % json.dumps(
						json.loads(sstore), sort_keys=True,
						indent=4,
						separators=(',', ': ')
					)
				)

				f.flush()
				f.close()
				model.save(filename)
				f = open(filename + ".store.pkl", "wb")
				cPickle.dump(self.store, f)
				f.close()

			except KeyboardInterrupt :
				exType, ex, tb = sys.exc_info()
				_dieGracefully(exType, tb)
				raise
			except :
				exType, ex, tb = sys.exc_info()
				_dieGracefully(exType, tb)
				raise
dataset/ETHPy150Open tariqdaouda/Mariana/Mariana/training/trainers.py/Trainer_ABC.start/swapped operands of `%`