Skip to content

Instantly share code, notes, and snippets.

@cuuupid
Created February 26, 2018 17:43
Show Gist options
  • Save cuuupid/e83405f38a8809bd763e179fbc65d732 to your computer and use it in GitHub Desktop.
Save cuuupid/e83405f38a8809bd763e179fbc65d732 to your computer and use it in GitHub Desktop.
Avoid HTTP Timeout
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