-
I'm running the following code: import time
from cheroot.wsgi import PathInfoDispatcher
from cheroot.wsgi import Server
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
time.sleep(10)
return 'Hello, World!'
server = Server(('0.0.0.0', 5000), PathInfoDispatcher({'/': app}), numthreads=1,
timeout=1, shutdown_timeout=1)
server.safe_start()
Did I misunderstand what |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
|
Beta Was this translation helpful? Give feedback.
-
I'm not sure I can fully follow your answer. Is the described behavior above under "What is the current behavior?" the expected behavior? |
Beta Was this translation helpful? Give feedback.
-
You wrote, that you might've misunderstood the purpose of these arguments, thus I've checked the code and described the actual behavior. It is not a bug. But if you want additional high-level timeout for requests it would require some additional coding. |
Beta Was this translation helpful? Give feedback.
-
Do you have an example when either timeout might be triggered? |
Beta Was this translation helpful? Give feedback.
-
Regarding your wish to terminate request processing after timeout, I'd say its nearly impossible:
You could reimplement such behavior within your app or use CherryPy. |
Beta Was this translation helpful? Give feedback.
-
@f11r Here's an idea of the decorator, which could help you with timeout checks, you'll just need to turn your handler into generator and split it into slices inserting yields between potentially slow parts and then In [18]: timeout_happened = False
In [29]: def h_decor(h):
...: from functools import wraps
...: @wraps(h)
...: def wrapper(inp):
...: h_iter = h(inp)
...: try:
...: while True:
...: if timeout_happened:
...: h_iter.throw(TimeoutError)
...: else:
...: res = next(h_iter)
...: except StopIteration:
...: return res
...: return wrapper
...:
In [42]: def hndlr(inp):
...: try:
...: # do hard work
...: print('before timeout')
...: global timeout_happened
...: timeout_happened = True
...: yield
...: print('timeout happened')
...: except TimeoutError:
...: print('timeout error got from decorator')
...:
In [43]: d_hndlr = h_decor(hndlr)
In [44]: d_hndlr('asfdsaf')
before timeout
timeout error got from decorator |
Beta Was this translation helpful? Give feedback.
timeout
is a socket-level timeout, for all the cases, please consult with socket documentation.shutdown_timeout
is time Cheroot waits to forcibly shut down the socket if its still alive after sending_SHUTDOWNREQUEST
to corresponding threads.accepted_queue_timeout
is time during which the incoming request must be put into request queue (which would happen if the queue is not full).Regarding your wish to terminate request processing after timeout, I'd say its nearly impossible:
TimeoutMonitor
, which i…