Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # acquire db connection from pool
- @app.before_request
- def get_connection():
- setattr(g, '__con__', MysqlHandler())
- @classmethod
- def get(cls, **kwargs):
- res = g.__con__.simple_query(cls.__table__, query_cond=kwargs)
- return cls(**res[0]) if res else None
- # commit db update after the request, if no exception
- @app.after_request
- def commit(response):
- if getattr(g, '__con__', None):
- g.__con__.commit()
- return response
- @copy_current_request_context
- def my_async_task():
- time.sleep(5)
- print 'I am g', g.__con__
- class TeamListView(Resource):
- # http GET handler, return all team members
- def get(self):
- gevent.spawn(my_async_task)
- all_groups = Team.all()
- return return_json(data=all_groups)
Add Comment
Please, Sign In to add comment