私はwsgiという簡単なプログラムを持っています。マルチプロセスでpythonのsimple_serverからmake_serverを実行するには?
from wsgiref.simple_server import make_server
import time
def application(environ, start_response):
response_body = 'Hello World'
status = '200 OK'
response_headers = [('Content-Type', 'text/plain'),
('Content-Length', str(len(response_body)))]
start_response(status, response_headers)
if environ['PATH_INFO'] != '/favicon.ico':
print "Time :", int(time.time())
if int(time.time()) % 2:
print "Even"
time.sleep(10)
else:
print "Odd"
return [response_body]
httpd = make_server('localhost', 8000, application)
httpd.serve_forever()
timestamp
がEven
であれば、コードごとに、それは10秒後に応答を送信するに。しかしtimestamp
がOdd
である場合、それは睡眠なしで直接応答を送るでしょう。
2つのリクエストを送信し、最初のリクエストでEven
モードでリクエストを送信すると、最初のリクエストが完了した後に2番目のリクエストが送信されます。
解決策を確認したところ、「マルチプロセスcan solve this problem. I set the apache configuration with
マルチプロセス. Then I get the response for
奇数without completing
偶発」リクエストが見つかりました。
をmake_server
の方法でsimple_server
モジュールに設定する方法を確認します。私はpython /usr/lib64/python2.7/wsgiref/simple_server.py
を実行すると、私は、出力を取得し、最後の数行は
wsgi.errors = <open file '<stderr>', mode 'w' at 0x7f22ba2a1270>
wsgi.file_wrapper = <class wsgiref.util.FileWrapper at 0x1647600>
wsgi.input = <socket._fileobject object at 0x1569cd0>
wsgi.multiprocess = False
wsgi.multithread = True
wsgi.run_once = False
wsgi.url_scheme = 'http'
wsgi.version = (1, 0)
ですだから私は、すべてのリクエストが進行中の場合はmake_serverはもっとして1つの要求を処理できるように、このmake_server
マルチプロセスを設定する方法を検索しました。
Thxです。
simple_serverは、トルネード、ツイスト、ピラミッドに真の並行性を求めたい場合には、Pythonのおもちゃです –
私はSOAPで1つのWebサービスを作成したいと思います。だから私はsoaplib 2.0をインストールし、その機能を使って私のサービスを公開しています。だから私は1つの要求を処理しているときに私は 'make_server'でサーバーを実行する場合、サーバーの2番目の要求を待たなければならないので、make_serverはマルチプロセスをサポートしていないと思いますか? – Nilesh