Guest User

Untitled

a guest
Feb 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. # acquire db connection from pool
  2. @app.before_request
  3. def get_connection():
  4. setattr(g, '__con__', MysqlHandler())
  5.  
  6. @classmethod
  7. def get(cls, **kwargs):
  8. res = g.__con__.simple_query(cls.__table__, query_cond=kwargs)
  9. return cls(**res[0]) if res else None
  10.  
  11. # commit db update after the request, if no exception
  12. @app.after_request
  13. def commit(response):
  14. if getattr(g, '__con__', None):
  15. g.__con__.commit()
  16.  
  17. return response
  18.  
  19. @copy_current_request_context
  20. def my_async_task():
  21. time.sleep(5)
  22. print 'I am g', g.__con__
  23.  
  24. class TeamListView(Resource):
  25. # http GET handler, return all team members
  26. def get(self):
  27. gevent.spawn(my_async_task)
  28. all_groups = Team.all()
  29. return return_json(data=all_groups)
Add Comment
Please, Sign In to add comment