Created
February 26, 2018 17:43
-
-
Save cuuupid/e83405f38a8809bd763e179fbc65d732 to your computer and use it in GitHub Desktop.
Avoid HTTP Timeout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sanic import Sanic | |
from sanic.response import stream | |
from sanic_cors import CORS, cross_origin | |
from time import sleep | |
app = Sanic() | |
CORS(app) | |
@app.route('/api', methods=['POST']) | |
async def serve(q): | |
var1 = 5 | |
var2 = 10 | |
async def slow(s, var1=var1, var2=var2): | |
for _ in range(var2): | |
s.write(' ') | |
sleep(var1) | |
s.write('done') | |
return stream(slow, content_type='text/plain', headers={ 'Transfer-Encoding': 'chunked' }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment