def end_run(): """Ends the run, broadcasts a refresh message to all clients""" # Send a stop run signal to fe_master. context = zmq.Context() stop_sck = context.socket(zmq.PUSH); conf = json.load(open(os.path.join(cwd, '../fast/config/.default_master.json'))) stop_sck.connect(conf['trigger_port']) stop_sck.send("STOP:") stop_sck.close() context.destroy() global running if running: running = False data_io.end_run() data = get_last_data() data['Events'] = data_io.event_count data['Rate'] = "%.1f" % data_io.rate now = datetime.datetime.now() data['End Date'] = "%02i/%02i/%04i" % (now.month, now.day, now.year) data['End Time'] = "%02i:%02i" % (now.hour, now.minute) db = connect_db(run_info['db_name']) db.save(data) sleep(0.1) broadcast_refresh() context.destroy() return redirect(url_for('running_hist'))
def end_run(): """Ends the run, broadcasts a refresh message to all clients""" # Send a stop run signal to fe_master. context = zmq.Context() handshake_sck = context.socket(zmq.REQ) handshake_sck.setsockopt(zmq.LINGER, 0); stop_sck = context.socket(zmq.PUSH) stop_sck.setsockopt(zmq.LINGER, 0) conf = json.load(open(os.path.join(cwd, '../fast/config/.default_master.json'))) stop_sck.connect(conf['trigger_port']) handshake_sck.connect(conf['handshake_port']) msg = "CONNECT" handshake_sck.send(msg) if (handshake_sck.recv() == msg): # Connection established. stop_sck.send("STOP:") handshake_sck.close() stop_sck.close() context.destroy() global running if running: running = False data_io.end_run() db = connect_db(run_info['db_name']) data = db[db['toc'][str(run_info['last_run'])]] data['Events'] = data_io.eventCount data['Rate'] = "%.1f" % data_io.rate now = datetime.datetime.now() data['End Date'] = "%02i/%02i" % (now.month, now.day) data['End Time'] = "%02i:%02i" % (now.hour, now.minute) print "%i events" % data_io.eventCount db.save(data) sleep(0.1) broadcast_refresh() context.destroy() return redirect(url_for('running_hist'))