bottleやflaskやjaprontoなどのpythonフレームワークにてwebserverをたちあげて
同じパスに同時にアクセスすると待ちが発生してしまうのですが、これを解消する方法はありませんでしょうか?
例↓
import asyncio from japronto import Application # This is a synchronous handler. def synchronous(request): return request.Response(text='I am synchronous!') # This is an asynchronous handler, it spends most of the time in the event loop. # It wakes up every second 1 to print and finally returns after 3 seconds. # This does let other handlers to be executed in the same processes while # from the point of view of the client it took 3 seconds to complete. async def asynchronous(request): for i in range(1, 4): await asyncio.sleep(1) print(i, 'seconds elapsed') return request.Response(text='3 seconds elapsed') app = Application() r = app.router r.add_route('/sync', synchronous) r.add_route('/async', asynchronous) app.run()
AとBという人が2名いたときに
http://localhost:8080/async
このアドレスをほぼ同時にアクセスしたら(若干Aが先にアクセスしてる)
Bの人の画面が表示させるのが約6秒後になってしまいます。(Aがアクセスしたときの処理を待っている)
これをAもBも同時にアクセスしたときに各々が3秒後に表示されるようにするためにはどうしたらよろしいでしょうか?
nodejsのような環境ではなく、pythonの環境で実装させてみたいです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/06 00:27
2018/06/06 01:06 編集
2018/06/06 02:01