def run_simulation_callback(n_clicks, simulation_days): print('run simulation (days %d)' % simulation_days) print(generate_cache_key(simulate_individuals)) set_variable('simulation_days', simulation_days) if n_clicks: set_variable('random_seed', n_clicks) df = simulate_individuals(only_if_in_cache=True) if df is not None: return render_results(df) if settings.RESTRICT_TO_PRESET_SCENARIOS: return [html.Div('Palvelussa ruuhkaa, osa simulaatiotoiminnallisuuksista on pois käytöstä')] existing_thread_id = session.get('thread_id', None) if existing_thread_id: cache.set('thread-%s-kill' % existing_thread_id, True) process = SimulationThread(variables=session.copy()) session['thread_id'] = process.uuid process.start() return [ dcc.Interval(id='simulation-output-interval', interval=500, max_intervals=60), html.Div(id='simulation-output-results'), ]
def integration_home(): session_ = session.copy() if "_ucam_webauth" in session_: del session_["_ucam_webauth"] if "_flashes" in session_: del session_["_flashes"] return render_template("integration.html", session=session_)
def run_simulation_callback(n_clicks, simulation_days): from flask import session from common import cache print('run simulation (days %d)' % simulation_days) set_variable('simulation_days', simulation_days) if n_clicks: set_variable('random_seed', n_clicks) df = simulate_individuals(only_if_in_cache=True) if df is not None: return render_results(df) existing_thread_id = session.get('thread_id', None) if existing_thread_id: cache.set('thread-%s-kill' % existing_thread_id, True) process = SimulationThread(variables=session.copy()) session['thread_id'] = process.uuid process.start() return [ dcc.Interval(id='simulation-output-interval', interval=500, max_intervals=60), html.Div(id='simulation-output-results'), ]
def user_logout(): tmp = session.copy() for i in tmp: del (session[i]) del tmp session['login'] = False return redirect(url_for('user.user_login'))
def getmapNewuser(): result_df = pd.DataFrame() if session.get('keyword') != None: result_df = getKeyWordsRecoms(session.get('keyword'), 5).toPandas() for key in session.copy(): session.pop(key, None) mp = folium.Map(location=[36.1699, -115.1398], zoom_start=12) for i, r in result_df.iterrows(): folium.Marker(location=[float(r.latitude), float(r.longitude)], popup=html.escape(r["business_name"]) + '<br>' + 'Stars: ' + str(r.stars) + '<br>' + 'Reviews: ' + str(r.review_count), icon=folium.Icon(color='green')).add_to(mp) return mp._repr_html_()
def create_session(username=None, staff=False): try: sess = sessions.get(request.remote_addr) if "username" in sess: return jsonify(error={"message": "SESSION ALREADY HAS ID/USERNAME"}) except: pass if username is None: username = request.json.get("username") session["username"] = username session["staff"] = staff sessions[request.remote_addr] = session.copy() return jsonify(data={"session_id" : session["username"], "staff" : session["staff"]})
def create_test_client(self, user): """ Create a test client with the permissions and an active session of the given user. """ with self.app.test_request_context(): db.session.add(user) db.session.commit() # Login the user and save the session login_user(user) session_copy = session.copy() # Re-create the session with a new test client with self.app.test_client() as c: with c.session_transaction() as sess: for k, v in session_copy.items(): sess[k] = v return c
def logged_in_user(db): app = create_app(TestConfig) user = User(username='******', email='*****@*****.**') with app.test_request_context(): db.session.add(user) db.session.commit() # Login the user and save the session login_user(user) session_copy = session.copy() # Re-create the session with a new test client with app.test_client() as c: with c.session_transaction() as sess: for k, v in session_copy.items(): sess[k] = v return c
def deco_func(*args, **kwargs): try: session_key = request.cookies.get(app.config['SESSION_COOKIE_NAME']) is_login = False print str(session.sid) + " == " + str(session_key) + " : " + str(session.sid == session_key) print 'session.__contains__("userid") : ' + str(session.copy()) if session.sid == session_key and session.__contains__('userid'): is_login = True if not is_login: print '로그인 필요' flash("login please.") return redirect('/') return f(*args, **kwargs) except Exception as e: print '에러 : ' + str(e) raise e
def mutate(root, info, random_seed=None): variables = session.copy() if random_seed is not None: variables['random_seed'] = random_seed for key, process in list(simulation_processes.items()): if process.exitcode is not None: process.join() del simulation_processes[key] if len(simulation_processes) >= 16: raise GraphQLError('System busy') process = SimulationProcess(variables=variables) run_id = process.cache_key process.start() if process.pid: print('Started process with PID %s (key %s)' % (process.pid, process.cache_key)) simulation_processes[process.cache_key] = process return dict(run_id=run_id)
def pubsub(): print("pubsub in.") p = r.pubsub() p.subscribe(['device']) cache = {} print("first cache:%s" % cache) def get_data(s, cache): print("get_data in.") for item in p.listen(): print(item) if item['type'] == 'message': data = item['data'] ds = hash_message(data.decode('utf8')) if 'ret' in ds: if ds['ret'] == 'error': if ds['state'] == 'using' and ds['user'] == s['id']: print('user: %s' % ds['user']) break cache['ret'] = 'success' yield 'data:%s\n\n' % data cache['ret'] = "error" cache['msg'] = "using" print("get_data out.") yield 'data:%s\n\n' % "the device is using." tmp = session.copy() resp = get_data(tmp, cache) next(resp) print(cache) if 'ret' in cache: print(cache['ret']) if cache['ret'] == 'error': print('ret:%s' % cache['ret']) p.unsubscribe('device') return make_response("%s" % cache['ret']) print("pubsub out.") return Response(resp, mimetype="text/event-stream")
def index(): for key in session.copy(): session.pop(key, None) return render_template('index.html')
* 判断是否存在 'name' in session * 获取数据 session['name'] * 如果数据不存在,抛出异常 KeyError * session部分方法 session.get(name,default) * 安全的取值 session.keys() session.values() session.items() session.fromkeys() session.copy() session.clear * session属性 new * 如果会话是新的,则该值为 True modified * session是否被修改(进行了CUD) * 如果是对session里面的对象,进行修改,该值不会发生变化,需要手动的修改该值 session['objects'].append(42) session.modified = True permanent * 如果设置为True,则会话持续app.permanent_session_lifetime秒.默认值为31天 * 如果设置为False(这是默认值),当用户关闭浏览器时,会话将被删除
def remove_session(): # the dictionary needs to be copied to avoid a runtime error sess = login_session.copy() for (key, value) in sess.items(): del login_session[key]
def reset_session(): for key in session.copy(): if key != 'csrf_token': del session[key] session.updated = True
def only_memeber(): return '회원만 접근가능한 페이지 입니다.' + session.get('userid')+ '님 반갑습니다. <br> 세션 만료시간 : '+ str(session.copy())
def map(): session_ = session.copy() return render_template("map.html", session=session_)