Accept a finite number of HTTP requests in Python app -


i new python , want build application can accept number of http requests, go on parse these requests , process data stored in body.

i have found lot of tutorials rest apis , ways create servers indefinitely accept incoming requests, however, not seem practice me start such server force stop after short amount of time. in addition, need compare data within request bodies determine when stop accepting requests, , had trouble storing data between request handler calls using flask.

my question this:

what practice accepting http requests in python, amount of requests received depends on data in each request body (such when requirement met, program can stop accepting connections , go on process stored request data)

try use flask.g store request counter, http://flask.pocoo.org/docs/0.10/api/#flask.g

if counter reach upper limit , shutdown flask how stop flask application without using ctrl-c

sorry, misunderstand, flask.g threadlocal in java, different between requests. in situation, think simple way use module variable

access_count = 0 def counter(func):     def other_func(*args, **kwargs):         global access_count         access_count = access_count + 1         return func(*args, **kwargs)     return other_func  @counter @app.route("/aaa") def a():     print "aa" @counter @app.route("/bbb") def b():     print "bb"  def main():     a()     b()     print access_count 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -